Is it possible to check if a url address starts with for example: http://www.odsavacky.cz/blog/wpcproduct/ ?
3 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
}
6 Comments
loveNoHate
I don't get the
indexOf() part. Can't you do if (window.location.href == 'http://www.odsavacky.cz/blog/wpcproduct/')?Barmar
That checks if the whole URL exactly matches, not just the beginning.
loveNoHate
Cool, got it! Was overreading the term start in the question anyway. ;)
Cătălin Rădoi
should be === -1, not == 0
Barmar
@CătălinRădoi That tests if it doesn't contain the string.
|