开发者社区 问答 正文

如何去除设置 location.hash 后的 # 号?

设置了 window.location.hash=“abc”后,url后面自动加上了“#abc”。这时候要怎么设置才能把“#abc”去掉呢?设置hash=“”只能去掉“abc”,还会残留一个#

展开
收起
杨冬芳 2016-06-16 12:48:47 3863 分享 版权
1 条回答
写回答
取消 提交回答
  • 码农|Coder| Pythonista

    history api(只支持现代浏览器)

    history.replaceState(null,'',location.pathname+location.search);
    location.replace(导致页面重新加载)

    location.replace(location.pathname+location.search);

    2019-07-17 19:40:42
    赞同 展开评论
问答地址: