Search code examples
jqueryurl

jQuery check current url


We are on page 'http://site.com/movies/moviename/'

How can we know, is there /movies/ in current url (directly after site's root)?


Code should give:

True for 'http://site.com/movies/moviename/'

And false for 'http://site.com/person/brad-pitt/movies/'


Thanks.


Solution

  • You can try the String object's indexOf method:

    var url = window.location.href;
    var host = window.location.host;
    if(url.indexOf('http://' + host + '/movies') != -1) {
       //match
    }