var myurl = window.location;
var pos = myurl.IndexOf("memberId");
if (pos = -1) {
alert("false");
} else {
alert("true");
}由于某些原因,我似乎不能让这个简单的方法工作。Chrome说'myurl不包含方法'indexOf'‘。有什么原因吗?
发布于 2010-12-15 23:22:22
也许是打字错误,但它应该是
myurl.indexOf小写i。
和location is an object,所以你想要:
var myurl = window.location.href;(以及人们在评论和其他答案中说的所有其他事情;)
更新:要查看对象具有哪些属性,只需在控制台中输入,在本例中为window.location:

发布于 2010-12-15 23:22:50
window.location返回一个对象。也许你想要window.location.pathname?:-)
这一行还有一个问题:
if (pos = -1)它应该是
if (pos == -1)发布于 2010-12-15 23:22:43
试试var myurl = window.location.pathname;
https://stackoverflow.com/questions/4451542
复制相似问题