Update browser's URL without reloading the page

…衆ロ難τιáo~ 提交于 2019-12-04 08:35:08

问题


Is it possible to change the URL shown in the browser's address bar without having the browser go to that page? Such as, for example, after updating a page's content via an AJAX call?

My understanding is that this is not possible, which is why sites such as twitter and facebook update the hash-tag on ajax calls.

That is until today, when I went on http://8tracks.com/ and started to play with the filter on the right hand side... turning different genres on and off, I noticed that even though it was doing ajax calls to refresh the content on the page, the URL was also being dynamically updated.

Does anyone know how they do this?

(aside, I'm currently using Chrome, but when I went back and looked again with IE9, I noticed that the URL was not being updated.. is this maybe a Chrome only thing?)


回答1:


This is possible in modern browsers by using the HTML5 History API:

history.pushState(null, null, '/some-path')

See https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history#The_pushState%28%29.c2.a0method

This works in Firefox, Chrome, Opera, Safari (not IE).




回答2:


also you can use Jquery history plugin. This will give support to html4 browsers as well.

Here is an article talking about it: http://veerasundaravel.wordpress.com/2011/12/02/change-browser-url-with-reloading-the-page-jquery-html5/

here is another question that gives more options: jQuery History Plugin



来源:https://stackoverflow.com/questions/7077264/update-browsers-url-without-reloading-the-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!