How to change URL in browser without navigating away from page?

后端 未结 2 1056
囚心锁ツ
囚心锁ツ 2020-11-29 04:23

I am writing a complex AJAX application at the moment and the entire site has clean URLs. At the moment PHP creates the basic layout for each page however I don\'t want to h

2条回答
  •  被撕碎了的回忆
    2020-11-29 04:37

    You can do it with history.pushState, but only in browsers that support it. Just try the following line in your browsers JavaScript-Console.

    history.pushState({},"URL Rewrite Example","https://stackoverflow.com/example")
    

    More on that in The pushState() method (Mozilla Developer)

    Similar question How do I, with JavaScript, change the URL in the browser without loading the new page?

提交回复
热议问题