Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check in javascript if url address start with defined string?

Tags:

javascript

Is it possible to check if a url address starts with for example: http://www.odsavacky.cz/blog/wpcproduct/ ?

like image 218
Daemon481 Avatar asked Feb 08 '26 00:02

Daemon481


1 Answers

Just use normal string searching:

// if the url begins with this string
if (window.location.href.indexOf('http://www.odsavacky.cz/blog/wpcproduct/') == 0) {
    // Do what you want
}
like image 199
Barmar Avatar answered Feb 12 '26 04:02

Barmar