【问题标题】:How to change the page url without reloading the page如何在不重新加载页面的情况下更改页面 url
【发布时间】:2020-04-20 16:27:39
【问题描述】:

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

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

但它并不适用于所有浏览器,并且 Firefox 将其标记为 insecure。 有没有其他方法可以在 JavaScript/jQuery/.htaccess/HTML 元标记

编辑:
(1):我想要一个不使用window.history.pushState的答案
(2): strong> 这些答案无济于事: how to chage url without redirect in javascript? , How do I modify the URL without reloading the page?

【问题讨论】:

标签: javascript jquery html .htaccess meta


【解决方案1】:

如果您想更改 url 但不想将此条目附加到浏览器历史记录中,可以使用 HTML5 replaceState:

if(window.history.replaceState){
   window.history.replaceState(STATEDATA, TITLE, URL);
}

【讨论】:

    猜你喜欢
    • 2017-12-13
    • 2020-10-04
    • 2020-12-29
    • 2020-06-27
    • 2016-10-28
    • 2013-07-07
    • 1970-01-01
    • 2011-11-27
    相关资源
    最近更新 更多