【问题标题】:How to remove part of the URL after loading加载后如何删除部分 URL
【发布时间】:2015-03-18 16:55:38
【问题描述】:

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

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

加载后不久,我需要删除查询字符串

【问题讨论】:

标签: jquery url query-string


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2019-10-09
    • 1970-01-01
    • 2017-08-02
    • 1970-01-01
    • 2018-04-07
    • 2017-03-22
    • 2020-08-24
    相关资源
    最近更新 更多