如何在不重新加载页面的情况下更改页面 url

How to change the page url without reloading the page

我想知道如何在不重新加载页面的情况下更改页面URL更改页面内容。 我已经使用了该代码 (JavaScript):

if(history.pushState){
  window.history.pushState("object or string", "Title", "/");
}else{
  document.location.href = "/";
}

但它并不适用于所有浏览器,Firefox 将其标记为 不安全。 在 JavaScript/jQuery/.htaccess[ 中还有其他方法可以做我想做的事吗=39=]/HTML 元标签

编辑:
(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);
}