1

I am in a page with url

https://mysite.com/tst/v1/my-app/var/$%5Btest_new_var%5D.

On click i want to change the url to

https://mysite.com/tst/v1/my-app/" without reloading the page.

How can i do that?

please help, Thanks.

Zeeshan
  • 1,659
  • 13
  • 17
Erma Isabel
  • 555
  • 2
  • 11
  • 25
  • @DanielNill there are perfectly valid reasons to do this if you want to create linkable ajax applications. – max Oct 30 '14 at 06:48

1 Answers1

3

In newer browsers that support history.pushState you can replace the url without reloading.

Lets say a user browses to http://example.com/ernie.html

window.history.pushState({ foo: "bar" }, "page 2", "bert.html");

Will change the address bar to http://example.com/bert.html, but won't cause the browser to load bert.html or even check that bert.html exists.

max
  • 96,212
  • 14
  • 104
  • 165
  • https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Manipulating_the_browser_history – max Oct 28 '14 at 05:12
  • This is useful when you are using ajax to load the page or do some searching ,you can retain the previous state by checking the get params – Arun Killu Oct 28 '14 at 05:24