jQuery检查当前的url

Jam*_*mes 10 url jquery

我们在页面上 'http://site.com/movies/moviename/'

我们怎么知道,是否有/movies/当前网址(直接在网站的根目录之后)?


代码应该给:

真的 'http://site.com/movies/moviename/'

而且是假的 'http://site.com/person/brad-pitt/movies/'


谢谢.

Jac*_*kin 14

您可以尝试String对象的indexOf方法:

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