[英]Completely remove hash from URL
有多种方法,具体取决于您的具体情况。
如果只想删除哈希值:
location.hash = '';
...但是这会将#
留在该位置。 (还将用户滚动到页面顶部。)要删除该内容:
location = location.pathname;
...但是这也会重新加载页面。 解决所有这些问题:
history.pushState({},'',location.pathname);
// back button returns to #example
要么
history.replaceState({},'',location.pathname);
// back button doesn't return to #example
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.