如何在加载后删除部分 URL

Mat*_*van 1 url jquery query-string

基本上我有一个被加载的网址

http://somewebsite.com/Staging/hello/index.php?action=viewByGrid&subdo=show&projectID=-1&stat=1&workStageID=-1
Run Code Online (Sandbox Code Playgroud)

加载后。我希望 URL 显示为

http://somewebsite.com/Staging/hello/index.php?action=viewByGrid
Run Code Online (Sandbox Code Playgroud)

我需要在我的document.ready()加载后不久删除查询字符串

Sei*_*Sys 5

使用history.replaceStatehistory.pushState。它得到了相当好的支持,并且可以满足您的需求。前者不会插入新的历史条目,只是修改当前的历史条目,而后者会为新的 URL 添加一个新的历史条目。前两个参数不重要,第三个是改变url的

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