2

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()

Sherlock
  • 7,525
  • 6
  • 38
  • 79
Matarishvan
  • 2,382
  • 3
  • 38
  • 68
  • possible duplicate of [jquery: change the URL address without redirecting?](http://stackoverflow.com/questions/6478485/jquery-change-the-url-address-without-redirecting) – hlscalon Jan 20 '15 at 12:48
  • see this link my be useful http://stackoverflow.com/questions/24307401/window-history-pushstate-refreshing-the-browser – Girish Jan 20 '15 at 12:52

1 Answers1

6

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);
});
SeinopSys
  • 8,787
  • 10
  • 62
  • 110