gpt4 book ai didi

javascript - 在 Safari 3+ 中将 window.location.hash 设置为 null 会导致它被设置为 #

转载 作者:行者123 更新时间:2023-11-30 06:49:46 28 4
gpt4 key购买 nike

在 Safari 3+ 中将 window.location.hash 设置为 null 会导致它被设置为 #,例如

window.location.hash = '#foo' => #foo

但是,

window.location.hash = null => #

如果将其设置为空字符串而不是 null,也会发生同样的情况。行为肯定发生在 Safari 3 + 4 中,不会发生在 FF 3 或 4 中。

有什么解决方法吗?诚然,这更多是出于审美动机,但我仍然希望在所有浏览器中保持一致的行为。

最佳答案

在 Safari 4(不知道 3)中,这将使 # 消失,并且页面不会重新加载。

window.location.hash = 'foo';
window.history.go(-1);

但是,它显然会扰乱浏览器历史记录。如果他们点击前进,它将带他们到 http://whatever.com/#foo .

关于javascript - 在 Safari 3+ 中将 window.location.hash 设置为 null 会导致它被设置为 #,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1359665/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com