0
我有一個活動,有2個步驟,每一步有自己的看法,第2步開始時,第一步結束,用戶在第二個視圖,在第2步,用戶不應該能夠點擊瀏覽器的後退按鈕。 也許它會很好,如果我可以給用戶顯示一條消息,但我不知道該怎麼做。mvc,如何防止點擊瀏覽器的後退按鈕?
我有一個活動,有2個步驟,每一步有自己的看法,第2步開始時,第一步結束,用戶在第二個視圖,在第2步,用戶不應該能夠點擊瀏覽器的後退按鈕。 也許它會很好,如果我可以給用戶顯示一條消息,但我不知道該怎麼做。mvc,如何防止點擊瀏覽器的後退按鈕?
要禁用後退按鈕,可以在第二頁上使用以下代碼。
window.onload = function() {
if (typeof history.pushState === "function") {
history.pushState("jibberish", null, null);
window.onpopstate = function() {
history.pushState('newjibberish', null, null);
// Handle the back (or forward) buttons here
// Will NOT handle refresh, use onbeforeunload for this.
};
}
else {
var ignoreHashChange = true;
window.onhashchange = function() {
if (!ignoreHashChange) {
ignoreHashChange = true;
window.location.hash = Math.random();
// Detect and redirect change here
// Works in older FF and IE9
// * it does mess with your hash symbol (anchor?) pound sign
// delimiter on the end of the URL
}
else {
ignoreHashChange = false;
}
};
}
}