我想知道如何更改页面URL ,而无需重新加载页面或更改页面内容。 我已经使用了该代码( JavaScript ):
if(history.pushState){
window.history.pushState("object or string", "Title", "/");
}else{
document.location.href = "/";
}
但是它并非在所有浏览器中都起作用,并且 Firefox 将其标记为不安全。 还有其他方法可以在 JavaScript / jQuery /中执行我想要的操作。 htaccess / HTML元标记 >
编辑:
(1):我想要一个不使用window.history.pushState
的答案
(2):这些答案无济于事:
how to chage url without redirect in javascript?
,How do I modify the URL without reloading the page?
答案 0 :(得分:1)
如果要更改URL,但又不想将此条目附加到浏览器历史记录中,则可以使用HTML5 replaceState:
if(window.history.replaceState){
window.history.replaceState(STATEDATA, TITLE, URL);
}