在DOM中首先运行document.location.hash =“”不会清除URL

时间:2011-08-01 08:37:59

标签: firefox url dom hash

document.location.hash =“”将哈希值设置为URL中的#。但是当我把它作为DOM中的第一件事时,它在Firefox中不起作用(至少是Firefox 5.0.1)。有什么想法吗?

尝试在Firefox和其他浏览器中访问http://www.sebastianrazola.com/test.html#thisshouldberemoved,看看我的意思。

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8" />
  <title>Hash test</title>
  <script type="text/javascript">
    document.location.hash="";
  </script>
</head>
<body>
  <p>The hash won't be set to <b>#</b> in Firefox. (At least in Firefox 5.0.1)</p>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

这是一个错误。 https://bugzilla.mozilla.org/show_bug.cgi?id=675587确切地说(我相信你提交了)。

如果您想暂时解决此问题,请在document.body.offsetWidth设置之前将location.hash添加到您的脚本中。这将创建可滚动的布局对象,其不存在会导致错误,从而阻止位置在没有错误修复的情况下进行更改。