Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/440.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Chrome对document.location.href的处理方式不同?_Javascript_Firefox_Google Chrome - Fatal编程技术网

Javascript Chrome对document.location.href的处理方式不同?

Javascript 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

在以下URL上:www.example.com/page/#2221

  • Chrome将返回
    www.example.com/page/#
    for
    document.location.href
  • Firefox将返回
    www.example.com/page/#2221
    for
    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/