【问题标题】:location.hash = window.location.hash does not work in Chromelocation.hash = window.location.hash 在 Chrome 中不起作用
【发布时间】:2019-02-28 13:26:18
【问题描述】:

我在初始页面加载后使用 JavaScript 动态创建锚点,我的重定向到锚点的解决方案正在调用:

location.hash = window.location.hash;

这很好用,正如在 Firefox 中的预期,它直接跳转到锚点而无需重新加载页面。但是,在 chrome 中进行测试时,这根本行不通。我已经尝试过我用来在 chrome 中工作的典型方法,例如,在超时中包装它,使用 href 而不是 hash,甚至使用 hash.substr(1) 来尝试让 chrome 玩球。

我迷路了,有什么建议吗?

【问题讨论】:

  • location.hashwindow.location.hash 完全相同——你能生成一个sn-p 代码来演示你在做什么吗?因为location.hash = window.location.hash; 就像在说a=a ...这没有意义
  • 试试let save = location.hash; location.hash= ''; location.hash = save;
  • 啊有趣,我在创建锚点的回调中使用它。 someCallBackFunction() { for loop to create anchors; location.hash = window.location.hash; //Jump to anchor now that it exists. }
  • 它由setTimeout(function() {save = location.hash; location.hash=''; location.hash=save;},300);工作

标签: javascript google-chrome web web-applications


【解决方案1】:
setTimeout(function() {save = location.hash; location.hash=''; location.hash=save;},300);

是@Jaromanda X 在 cmets 中给出的公认方法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-06-15
    • 1970-01-01
    • 2013-07-05
    • 1970-01-01
    • 2012-01-09
    • 2012-01-10
    • 2014-09-02
    相关资源
    最近更新 更多