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?

2
  • I dont understand why we cant use history Commented Jul 28, 2016 at 1:24
  • @TrevorClarke, because the page loads for the first time and has no history list. Commented Jul 28, 2016 at 1:28

3 Answers 3

7

You can use this

var url= document.location.href;
window.history.pushState({}, "", url.split("?")[0]);
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

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
});

Comments

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.