2016-07-28 93 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]);