从网址中删除hash

从网址中删除hash,第1张

从网址中删除hash

更新的答案

history.pushState("", document.title, window.location.pathname);

…,或者,如果您想维护搜索参数:

history.pushState("", document.title, window.location.pathname + window.location.search);

原始答案,不要使用这个,badwrongfun

var loc = window.location.href,    index = loc.indexOf('#');if (index > 0) {  window.location = loc.substring(0, index);}

…但这为您刷新了页面,刚到达那里似乎有点不礼貌。咧着嘴笑,似乎是最好的选择。



欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5588066.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-14
下一篇2022-12-14

发表评论

登录后才能评论

评论列表(0条)

    保存