window.location.search.substring在ie8中不工作

window.location.search.substring is not working in IE 8

本文关键字:工作 ie8 location search substring window      更新时间:2023-09-26

你能解决我的问题吗

window.location.search。substring在ie8中不工作

文德兰花

可能相关:

Internet explorer(至少v9,这是我在这里测试的)不填充位置。当前面有散列(#)时进行搜索,并将所有内容打包到位置。散列。

这是我的解决方案:

var query  = window.location.search.substring(1);
if (!query) {
    var hash = window.location.hash;
    query = hash.slice(hash.indexOf('?') + 1);
}

我读到:

Location对象有一个toString方法返回当前URL。你也可以给window.location分配一个字符串。这意味着您可以使用窗口。在大多数情况下,就像它是一个字符串一样。有时候,例如当你需要调用一个String方法时,你必须显式地调用toString

https://developer.mozilla.org/en/DOM/window.location

所以我在想:

window.location.search.toString().substring(...) ?

如果你把它改成document.location.search.substr