我想看看我现在的网址,例如:检查URL包含文本和括号
http://www.dummy.com/subpageone/pagetwo.html?ineedthis[andthis]&butnotthis
我想要一个alert
如果我得到确切ineedthis[andthis]
到目前为止我
if (window.location.href.indexOf("ineedthis") > -1) {
alert("your url contains it");
}
但是这还不够。我如何检查[andthis]
?我尝试了一些变化,但没有运气。
indexOf("ineedthis\[andthis\]")
indexOf("ineedthis%5andthis%5D")
if (/ineedthis\[andthis\]/.test(window.location.href))
感谢您的任何建议。
'的indexOf( “ineedthis [andthis]”)'对我来说工作正常 - 回报指数45,在你给的例子URL。另外,不需要转义方括号。 – Utkanos
可能是你用'window.location.href'获得编码url。在比较之前先尝试解码它。 – vijayP