【发布时间】:2019-02-28 13:26:18
【问题描述】:
我在初始页面加载后使用 JavaScript 动态创建锚点,我的重定向到锚点的解决方案正在调用:
location.hash = window.location.hash;
这很好用,正如在 Firefox 中的预期,它直接跳转到锚点而无需重新加载页面。但是,在 chrome 中进行测试时,这根本行不通。我已经尝试过我用来在 chrome 中工作的典型方法,例如,在超时中包装它,使用 href 而不是 hash,甚至使用 hash.substr(1) 来尝试让 chrome 玩球。
我迷路了,有什么建议吗?
【问题讨论】:
-
但
location.hash与window.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