Praveen D
Praveen D

Reputation: 2377

Remove parameter from url using Javascript

I wan to remove parameter from URL without reloading or refreshing page.

I used below code for that, and it's working fine.

jQuery(document).ready(function($) {    
    window.history.pushState("", "", "/" );
});

But problem is if I click on browser back button I can see parameters in url.

Upvotes: 1

Views: 339

Answers (1)

Alexander O'Mara
Alexander O'Mara

Reputation: 60507

That's because pushState adds a new entry to the browser history.

Use replaceState instead, to replace the current entry.

jQuery(document).ready(function($) {    
    window.history.replaceState("", "", "/" );
});

Upvotes: 7

Related Questions