Alex Rivera | Logout

How to change browser address bar without reloading page - HTML/Javascript

Asked 2011-04-09T21:03:32.097
35

Possible Duplicate:
How does GitHub change the URL but not the reload?

Hi folks,

I have noticed that Github.com does not force users to download webpages when browsing repositories, but instead uses AJAX in order to refresh the page content.

Github also changes the browser address bar to the real address representing the content. I have no idea how to implement this if not by using # hashtags within the url.


In short: github uses ajax to load new webpages, without using hashtags. How do they accomplish this?


Any ideas?

Edit
Report

1 Answer

48

By using:

window.history.pushState("string", "Title", "newUrl");

This is new in HTML 5.

Your url will change to newUrl without reloading the page.

Note: title arg in the method will not change the Title of the html page. This is used to name the page in the browser history, incase u go back and then go forward.

answered 2011-04-09T21:07:17.747

Your Answer