Javascript:在不刷新页面的情况下更改Url

Javascript: Change Url without refreshing the page

本文关键字:情况下 Url 刷新 Javascript      更新时间:2023-09-26

我在一个带有url 的页面中

https://mysite.com/tst/v1/my-app/var/$%5Btest_new_var%5D.

点击后,我想将url更改为

https://mysite.com/tst/v1/my-app/" without reloading the page.

我该怎么做?

请帮忙,谢谢

在支持history.pushState的较新浏览器中,您可以在不重新加载的情况下替换url。

假设用户浏览到http://example.com/ernie.html

window.history.pushState({ foo: "bar" }, "page 2", "bert.html");

将地址栏更改为http://example.com/bert.html,但不会导致浏览器加载bert.html,甚至不会检查bert.html是否存在。