Search code examples
javascripturllocationobject-address

Rewrite document.location without loading


I am developing a system which is 100% ajax, except of course, the first request.

I am interested in changing the address in document.location, using javascript. But I don't want the browser to load the page on that "new" location.

Does anyone know how I can do this?


Solution

  • To rewrite the entire location and not just the "hash" part, browser history API can be used, although currently it only seems to be supported in Gecko 1.9.3/Firefox 4.

    history.replaceState({}, document.title, url)