2016-07-28 91 views
2

页删除URL参数我有这样的URL时,临时密码的用户登录。无需重新加载

user.html?change=yes#passwordwrap 

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

user.html 

有没有可能的方法来做到这一点?没有使用历史记录,因为该页面是第一次加载并且没有历史记录列表。一个简单的方法?

+0

我不明白为什么我们不能用历史 –

+0

@TrevorClarke,因为在页面加载的第一次,没有历史记录列表。 –

回答

0

尝试......如果你面对问题与F/W & B/W按钮然后使用replaceState而非pushState的。

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

当后退按钮在浏览器中按下

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

http://stackoverflow.com/22753103#22753103 
0

这是改变网址 - :

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

本页面URL将改变事件被解雇

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

您可以使用此

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