Updating address bar with new URL without hash or reloading the page [duplicate] Updating address bar with new URL without hash or reloading the page [duplicate] google-chrome google-chrome

Updating address bar with new URL without hash or reloading the page [duplicate]


You can now do this in most "modern" browsers!

Here is the original article I read (posted July 10, 2010): HTML5: Changing the browser-URL without refreshing page.

For a more in-depth look into pushState/replaceState/popstate (aka the HTML5 History API) see the MDN docs.

TL;DR, you can do this:

window.history.pushState("object or string", "Title", "/new-url");

See my answer to Modify the URL without reloading the page for a basic how-to.


Changing only what's after hash - old browsers

document.location.hash = 'lookAtMeNow';

Changing full URL. Chrome, Firefox, IE10+

history.pushState('data to be passed', 'Title of the page', '/test');

The above will add a new entry to the history so you can press Back button to go to the previous state. To change the URL in place without adding a new entry to history use

history.replaceState('data to be passed', 'Title of the page', '/test');

Try running these in the console now!


Update to Davids answer to even detect browsers that do not support pushstate:

if (history.pushState) {  window.history.pushState("object or string", "Title", "/new-url");} else {  document.location.href = "/new-url";}