gpt4 book ai didi

javascript - 如何清除窗口哈希而不重新加载?

转载 作者:行者123 更新时间:2023-11-27 22:37:19 25 4
gpt4 key购买 nike

我有一个用户可以访问的网址 http://www.test.com/test/test#design/test

我想从 url 中删除哈希值而不重新加载页面,以便用户现在位于 http://www.test.com/test/test

如何使用 javascript/jquery 做到这一点?

最佳答案

尝试 window.history.pushState('', '/', window.location.pathname); 并回退到 window.location.hash = '' if不支持推送状态,但这会留下尾随 #。

if(window.history.pushState) {
window.history.pushState('', '/', window.location.pathname)
} else {
window.location.hash = '';
}

关于javascript - 如何清除窗口哈希而不重新加载?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39002991/

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