How to manipulate url with javascript and jquery?

I want to make a page with a lot of Javascript interactions. However, as the user navigates the page, the URL should also change. That way, when the user shares the URL or saves it, he can lead him to the actual state he was in.

How can i do this?

Examples:

myapp.com/page1

myapp.com/page2

+4
javascript jquery url
Jul 06 2018-11-11T00:
source share
4 answers

pushState as shown on github

+6
Jul 06 '11 at 19:08
source share
— -

Answer to this SO question: Change the URL in the browser without loading a new page using JavaScript

+3
Jul 06 2018-11-11T00:
source share

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

+2
Jul 06 '11 at 19:08
source share

Set this value: window.location.href

  window.location.href = "myapp.com/page2"; 
0
Jul 06 '11 at 19:09
source share



All Articles