删除url参数而不重新加载页面

时间:2016-07-28 01:20:00

标签: jquery html html5 url parameters

当用户使用临时密码登录时,我有此URL。

user.html?change=yes#passwordwrap

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

user.html

有可能这样做吗?不使用历史记录,因为页面是第一次加载而没有历史记录列表。一个简单的方法?

3 个答案:

答案 0 :(得分:1)

您可以使用此

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

答案 1 :(得分:0)

试试这个......如果你遇到F / W& amp; B / W按钮然后使用replaceState而不是pushState。

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

此页面网址将更改为:

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

http://stackoverflow.com/22753103#22753103

答案 2 :(得分:0)

这是用于更改网址

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
});
相关问题