3

Is it possible to change the entire URI of a page without reloading the page and actually going to the new URI? I know we can change the URL relative to the root domain, i.e. stackoverflow.com -> stackoverflow.com/asdf

Can this be done?

stackoverflow.com -> quora.com


I'm asking to make sure this is not possible.

EDIT: This question is different because I am asking if it's possible to change not just the path after the domain but the domain itself.

earllee
  • 285
  • 3
  • 11
  • 1
    I think that question addresses modifying URI without changing the domain name, i.e. stackoverflow.com -> stackoverflow.com/asdf – earllee Jun 24 '13 at 17:57
  • I hope [this post](http://stackoverflow.com/questions/824349/modify-the-url-without-reloading-the-page) helps. – Ricardo Saraiva Jun 24 '13 at 17:58

3 Answers3

4

Looks like it is NOT possible to change the domain, by design:

http://badassjs.com/post/840846392/location-hash-is-dead-long-live-html5-pushstate

Quoting the article:

window.history.pushState(data, "Title", "/new-url");

The last argument is the new URL. For security reasons you can only change the path of the URL, not the domain itself.

Community
  • 1
  • 1
Dave Swersky
  • 34,502
  • 9
  • 78
  • 118
1

Answering you question of whether the following can be done:

stackoverflow.com -> quora.com

Using the HTML history API one is only allowed to push states to within urls of the same domain, thus the answer is no.

Raj Nathani
  • 2,805
  • 1
  • 20
  • 19
0

Struggled with this issue before and couldn't find a way of doing it without reload... It's a part of the Location object http://www.w3schools.com/jsref/obj_location.asp . It reloads the page even if you change the query params, that makes sense, being a different URL in the end. The only thing you can do so far is to play with the # (hash) params.

One thing that might help you is the HTML5 History API http://html5demos.com/history . It modifies the url as you need in a way...but only for subdomains.