Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 742
RadiantHex Avatar asked Apr 09 '11 21:04

RadiantHex


People also ask

How do I use Javascript to modify the URL without reloading the page?

history. pushState({page: "another"}, "another page", "example. html"); This will change the URL, but not reload the page.

How do I change URL without reloading?

replaceState() method The replaceState() is another method that updates the URL without reloading the page. It works exactly the same way as pushState() , but replaces the existing browser history entry instead of adding a new one.

Which method is used to change the address in address bar of the browser?

HTML5 History API allows browsers to change the URL in browser address bar without reloading or refreshing the page using pushState function. The pushState method works similar to window.


2 Answers

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.

like image 98
euphoria83 Avatar answered Oct 01 '22 03:10

euphoria83


Have a look at the HTML5 history api. If you plan to use it, getting a library wrapping it and maybe even adding a fallback to location hashes would be a good idea.

https://github.com/browserstate/history.js looks not bad from a quick look at it.

like image 30
ThiefMaster Avatar answered Oct 01 '22 01:10

ThiefMaster