【问题标题】:Remove url parameter without page reloading删除 url 参数而不重新加载页面
【发布时间】:2016-07-28 01:20:00
【问题描述】:

当用户使用临时密码登录时,我有这个网址。

user.html?change=yes#passwordwrap

因此用户可以立即更改密码。保存新密码后,应删除 url 中的现有参数。应该是:

user.html

有没有可能的方法呢?不使用历史,因为该页面是第一次加载并且没有历史列表。一个简单的方法?

【问题讨论】:

  • 我不明白为什么我们不能使用历史记录
  • @TrevorClarke,因为页面是第一次加载并且没有历史列表。

标签: jquery html url parameters


【解决方案1】:

你可以用这个

var url= document.location.href;
window.history.pushState({}, "", url.split("?")[0]);

【讨论】:

    【解决方案2】:

    试试这个...如果您遇到 F/W 和 B/W 按钮问题,请使用 replaceState 而不是 pushState。

        window.history.pushState("object or string", "Title", "/"+window.location.href.substring(window.location.href.lastIndexOf('/') + 1).split("?")[0]);
    

    此页面 URL 将从:

    http://stackoverflow.com/questions/22753052/remove-url-parameters-without-refreshing-page/22753103#22753103
    

    http://stackoverflow.com/22753103#22753103
    

    【讨论】:

      【解决方案3】:

      这是用于更改网址

      window.history.pushState({ "html": "<h2>Hai</h2>", "pageTitle": "BuyOnline" }, "", '/buyonline/productview?param1=1&param2=2');
      

      在浏览器中按下后退按钮时 - 触发此事件

      window.addEventListener('popstate', function (event) {
          window.location.reload(); -- you can put your code here
      });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-05-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-01-14
        • 1970-01-01
        • 2018-03-29
        相关资源
        最近更新 更多