如何在加载后删除部分 URL

How to remove part of the URL after loading

基本上我有一个 url 可以加载

http://somewebsite.com/Staging/hello/index.php?action=viewByGrid&subdo=show&projectID=-1&stat=1&workStageID=-1

加载后。我希望 URL 显示为

http://somewebsite.com/Staging/hello/index.php?action=viewByGrid

我需要删除查询字符串,加载到我的 document.ready()

后不久

使用history.replaceStatehistory.pushState。它得到了很好的支持,可以做你想做的事。前者不会插入新的历史条目,只是修改当前的,而后者为新的URL添加新的历史条目。前两个参数不重要,第三个是什么改变了url

$(document).ready(function(){
   var href = window.location.href,
       newUrl = href.substring(0, href.indexOf('&'))
   window.history.replaceState({}, '', newUrl);
});