Javascript Chrome对document.location.href的处理方式不同?
在以下URL上:www.example.com/page/#2221Javascript Chrome对document.location.href的处理方式不同?,javascript,firefox,google-chrome,Javascript,Firefox,Google Chrome,在以下URL上:www.example.com/page/#2221 Chrome将返回www.example.com/page/#fordocument.location.href Firefox将返回www.example.com/page/#2221fordocument.location.href 是否有另一种方法可以让它们都返回www.example.com/page/#2221?文档。不推荐使用位置。尝试改用window.location.href。这样的东西怎么样 functi
- Chrome将返回
forwww.example.com/page/#
document.location.href
- Firefox将返回
forwww.example.com/page/#2221
document.location.href
是否有另一种方法可以让它们都返回
www.example.com/page/#2221
?文档。不推荐使用位置。尝试改用window.location.href
。这样的东西怎么样
function getUrl() {
var location = document.location.href,
locationLength = location.length,
hash = document.location.hash;
if (hash
&& location.substring(locationLength - 1, locationLength) == '#') {
location += hash;
}
return location;
}
它们在Firefox 3.6.13和Chrome9中返回相同的内容
尽管我一直使用window.location
window.location.href返回www.example.com/