我想知道如何在不重新加载页面 或更改页面内容 的情况下更改页面 URL。 我已经在使用该代码 (JavaScript):
if(history.pushState){
window.history.pushState("object or string", "Title", "/");
}else{
document.location.href = "/";
}
但它并不适用于所有浏览器,Firefox 将其标记为不安全。 在JavaScript/jQuery/.htaccess/HTML meta tags中还有其他方法可以做我想做的事吗p>
编辑:
(1): 我想要一个不使用 window.history.pushState
的答案
(2):这些答案没有帮助:
how to chage url without redirect in javascript?
, How do I modify the URL without reloading the page?
最佳答案
如果您想更改 url 但不想将此条目附加到浏览器历史记录,则可以使用 HTML5 replaceState:
if(window.history.replaceState){
window.history.replaceState(STATEDATA, TITLE, URL);
}
关于javascript - 如何在不重新加载页面的情况下更改页面 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59556010/