indexOf not working
var myurl = window.location;
var pos = myurl.IndexOf("memberId");
if (pos = -1) {
alert("false");
} else {
alert("true");
开发者_JAVA技巧 }
For some reason I can't seem to get this simple method to work. Chrome says 'myurl does not contain the method 'indexOf''. Any reason?
Maybe typo but it should be
myurl.indexOf
lowercase i.
And location is an object, so you want:
var myurl = window.location.href;
(and all the other things people say in the comments and other answers ;))
Update: To see what kind of properties an object has, just type, in this case, window.location in the console:

window.location returns an object. Perhaps you wanted window.location.pathname? :-)
There's also a problem with this line:
if (pos = -1)
It should be
if (pos == -1)
try var myurl = window.location.pathname;
var myurl = window.location.toString();
加载中,请稍侯......
精彩评论