![](/img/trans.png)
[英]Current URL hashchange event append new hash to target URL and link out to it
[英]Remove URL hash (not as variable) for hashchange event
我正在使用jQuery hashchange
事件,我页面中的每个按钮都使用此代码,如链接到另一个页面:
window.location.hash = '#anotherpage';
当我需要返回主页时, location.hash
会在我的URL中留下哈希字符(#),即使是location.hash = null
或location.hash = ""
有没有人知道如何在这种情况下删除哈希?
编辑:
正如Dsafds和Daniel所说,如果我使用window.location.hash = "#"
,只返回我的主页很容易。 问题是主页链接中的字符(#),用于其他页面,如#contact,是正常的,但我的主页也有哈希(site.com/#)。 我需要删除它。 还有其他想法吗? 谢谢!
您可以使用它返回主页:
window.location.hash="/" || window.location.hash="/home"
在你的情况下:
window.location.hash = "#"
我为你遇到的问题做了一个解决方法..删除哈希。
因此,当您更改“位置”时,您可以设置完整 URL。 例如:
假设你想进入登录页面:
window.location.href = "https://mysite/#/login"
现在你想回到主页! 然后你可以这样做:
window.location.href = "https://mysite/"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.