Reputation: 2422
Basically i have a url which gets loaded
http://somewebsite.com/Staging/hello/index.php?action=viewByGrid&subdo=show&projectID=-1&stat=1&workStageID=-1
After loading. I want the URL to be shown as
http://somewebsite.com/Staging/hello/index.php?action=viewByGrid
I need to remove the query string, soon after loading in my document.ready()
Upvotes: 2
Views: 4555
Reputation: 8937
Use history.replaceState
or history.pushState
. It's fairly well supported, and does what you want. The former will not insert a new history entry and just modify the current one, while the latter adds a new history entry for the new URL. The first two parameters are not important, the third is what changes the url
$(document).ready(function(){
var href = window.location.href,
newUrl = href.substring(0, href.indexOf('&'))
window.history.replaceState({}, '', newUrl);
});
Upvotes: 6