3

I have this url when the user login with temporary password.

user.html?change=yes#passwordwrap

So user can immediately change the password. After saving the new password, it should remove the existing parameter in the url. Should be:

user.html

Is there a possible way to do it? Without using history because the page is first time to load and no history list. A simple approach?

c.k
  • 1,075
  • 1
  • 18
  • 35

3 Answers3

6

You can use this

var url= document.location.href;
window.history.pushState({}, "", url.split("?")[0]);
Haresh Vidja
  • 8,340
  • 3
  • 25
  • 42
0

Try this... if you face problem with F/W & B/W button then use replaceState rather than pushState.

    window.history.pushState("object or string", "Title", "/"+window.location.href.substring(window.location.href.lastIndexOf('/') + 1).split("?")[0]);

This page URL will change from:

http://stackoverflow.com/questions/22753052/remove-url-parameters-without-refreshing-page/22753103#22753103

To

http://stackoverflow.com/22753103#22753103
Zigri2612
  • 2,279
  • 21
  • 33
0

This is for changing url

window.history.pushState({ "html": "<h2>Hai</h2>", "pageTitle": "BuyOnline" }, "", '/buyonline/productview?param1=1&param2=2');

When back button pressed in the browser - this event is fired

window.addEventListener('popstate', function (event) {
    window.location.reload(); -- you can put your code here
});
Arun Prasad E S
  • 9,489
  • 8
  • 74
  • 87