How to check string in current URL with javascript?
This question already has an answer here:
what about this? The regular expression defined at the first line is tested against the URL:
var myRe = //series//; //regular expression to use
if(myRe.test(window.location.href)){
alert("matching");
}else{
alert("not matching");
}
if you want to test for the whole URL (and really want to use a regular expression for that), you could replace the first line with
var myRe = /^http://mywebsite/series/2545-abc$/;
If you remove the dollar sign at the end, modifications at the end of the URL are accepted as well (eg http://mywebsite/series/2545-abc/foo.html
)
上一篇: URL的最后一部分