Change URL in address bar without having to reload

This question already has an answer here:

  • Modify the URL without reloading the page 18 answers

  • You can in newer browsers; in older ones, you can only change the hash. This seems like a good article on the topic: http://html5doctor.com/history-api/


    What you are looking for is the History API HTML5 provides. It comes with functionality like history.pushState(...) , history.popState(...) , which lets you dynamically change the URL without having to assign a new URL altogether.

    It is used by many sites, including, I suspect, Facebook itself, where if you open a chat box, and navigate between pages, the chat box doesn't reload. It means that all new content are being fetched through Ajax, but then the URL won't change, would it? But it does. I think they do it through history.pushState(...) , where you just push a new state into the History stack, and it changes only a certain part of the page. You will find an excellent tutorial here.

    链接地址: http://www.djcxy.com/p/70294.html

    上一篇: 如何加载页面而不重新加载?

    下一篇: 在地址栏中更改网址,无需重新加载