5

I want to make a page with a lot of Javascript interactions. However, while a user navigates through the page the URL must change too. So, when the user shares the URL or saves it, it can lead him to the actual state he was.

How can I do that?

Examples:

myapp.com/page1

myapp.com/page2

4 Answers 4

8

pushState, as seen on github

Sign up to request clarification or add additional context in comments.

2 Comments

It gracefully degrades in browsers that haven't yet caught up with pushState.
yeah. it's really nice feature! although in this particular case the old technique fits better with my needs, i guess this is, after all, the best choice for this problem.
4

Answered by this SO question: Change the URL in the browser without loading the new page using JavaScript

Comments

2

The only part of the url (or location) that you can change without reloading the page, is the hash. That is the part behind the #. Many ajax enhanced applications make use of this, including Twitter. You can change this hash on the go, and interpret the hash tag on page load to initialize the page to the correct state.

3 Comments

Thanks to pushState, that isn't true any more (at least in most browsers). Manipulating the hash like that has significant drawbacks
Well, it is supported in the latest FF and partially in Chrome. Too bad for IE and all mobile browsers, but hey, who uses them.
It's fully supported in Chrome, and Opera, Safari has partial support as does Mobile Safari; Opera Mobile and Android Browser support it.
-1

Set this value: window.location.href

  window.location.href = "myapp.com/page2";

1 Comment

It will cause the page to be reloaded, which is probably undesirable in the situation described by the OP.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.