我想更改以下示例 URL
http://www.mydomain.net/site?argument1=test1&argument2=test2#anchor
到
http://www.mydomain.net/site?argument1=test1&argument2=test2
使用 JavaScript。我最好怎么做?
编辑:对于“ anchor ”和其他文本元素,我指的是通用元素。所以 anchor 也可以是另一个文本。对不起。
最佳答案
如果您尝试更改当前 位置的 anchor ,最好更改window.location.hash
:
window.location.hash = '';
在某些浏览器中,这将避免在 URL 更改时重新加载页面。
关于javascript - 通过 JavaScript 删除 anchor ,但不删除参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5129178/