I either dreamt about chrome (dev channel) implementing a way to update the address bar via javascript (the path, not domain) without reloading the page or they really have done this.

However, I can't find the article I think I read.

Am I crazy or is there a way to do this (in Chrome)?

p.s. I'm not talking about window.location.hash, et al. If the above exists the answer to this question will be untrue.

3 upvote
  flag
upvote
  flag
@tobiaskienzler When that question was originally asked back in 2009, it was not possible. – David Murdoch
1 upvote
  flag
Of course not. But now it is, the questions ask for the same. A shame though that the other one has an outdated answer accepted (by you, I noticed)... You know what? Let's dupe-close the other way around, no-one said the "original" has to be the older one, in fact there are precedents – Tobias Kienzler
upvote
  flag
@tobiaskienzler, the other question doesn't have an outdated accepted answer. – David Murdoch
upvote
  flag
ok, not outdated, but more complicated. Still, the two questions do appear to be pretty much the same to me, but maybe I'm missing a nuance here... – Tobias Kienzler
upvote
  flag
@TobiasKienzler it's a 6 years old question, why you have to bother with this question? Just enjoy the amazing answer and implement it on your application. For 6 years thousands of SO users agreed that it's an amazing questions, please leave it as it is. – Imam Assidiqqi

3 Answers 11

up vote 701 down vote accepted

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.

3 upvote
  flag
Ah, the functionality is in WebKit and landed a few months ago <bugs.webkit.org/show_bug.cgi?id=36152>;. Nice find! – oldestlivingboy
5 upvote
  flag
this is now used by github, while tree navigation – Valerij
1 upvote
  flag
@Vprimachenko: Yup. And they break my back button every once in a while. – David Murdoch
upvote
  flag
This can now be done in Chrome, Safari, FF4+, and IE10pp3+! (From David Murdoch's answer to //allinonescript.com/questions/824349/… ) – Zach Lysobey
upvote
  flag
What about IE9 and below? Any similar solutions for them? – shubniggurath
upvote
  flag
There are all sorts of history hacks out there. See this SO question for more info: //allinonescript.com/questions/2358928/… – David Murdoch
upvote
  flag
being able to store objects related to the history is frakkin great as well! – roberthuttinger
8 upvote
  flag
Protip: you can use relative paths with these functions as well (e.g. ../new-url or ../../new-url. They seem to do what you would expect in Chrome at least. – Mahn
upvote
  flag
I'd like to add that window.replaceState is much easier to set up and often preferable, e.g. when you want to update the URL after the user changes the value of some dropdown or search field. If you want to use pushState, then you also need to properly support onpopstate event. – Kos

Changing only what's after hash - old browsers

document.location.hash = 'lookAtMeNow';

Changing full URL (the domain and protocol must be the same as original!) Chrome, Firefox, IE10+

history.pushState('data to be passed', 'Title of the page', '//allinonescript.com/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', '//allinonescript.com/test');

Try running these in the console now!

6 upvote
  flag
replaceState was exactly what I needed, thanks for expanding on original response. – meetalexjohnson
2 upvote
  flag
This is so quick and to the point, it needs more upvotes. – moodboom
upvote
  flag
'the domain and protocol must be the same as original!' this prevent some fishing site to change the address bar url. – Tianqing

Update to Davids answer to even detect browsers doesn't support pushstate:

if (history.pushState) {
  window.history.pushState("object or string", "Title", "/new-url");
} else {
  document.location.href = "/new-url";
}
upvote
  flag
document.location.href reloads the page – paullb
1 upvote
  flag
@paullb that's a fallback for older browsers that wouldn't support any way to do without reloading – Cœur

Not the answer you're looking for? Browse other questions tagged or ask your own question.