如何从URL地址检索变量? 我正在使用此代码,但它无法正常工作:
var x=window.location;
var y = x.indexOf('#', 0);
x=x.substring(y,x.length);
收到以下错误:
Error: x.indexOf is not a function
答案 0 :(得分:3)
您收到错误,因为window.location
是一个对象,而不是一个字符串。请尝试window.location.hash
获取#
之后的部分。
答案 1 :(得分:3)
你想要的不是window.location而是window.location.href
不过,我会使用window.location.hash