0
我希望頁面在顯示msgBox時停止重定向,並等到直到用戶按下了框上的按鈕。顯示msgbox後停止頁面重定向
我可以在頁面卸載時顯示msgbox,但仍然可以將頁面重定向到另一個網頁,而無需等待用戶的輸入。
<script>
$(window).bind('beforeunload', function() {
msgbox();
});
function msgbox() {
$.msgBox({
title: "Confirmation",
content: "Do you agree with the information provided?",
type: "confirm",
buttons: [{ value: "Yes" }, { value: "No" }],
success: function (result) {
if (result == "Yes") {
window.location.replace("somepage/controller/func2");
} else {
window.location.replace("somepage/controller/func1");
}
}
});
}
</script>
但是現在它顯示一條提示「您所做的更改可能無法保存」,並帶有Leave和Stay選項。點擊停留後,它顯示msgbox。 –
@SahibUzZaman那麼,'beforeunload'事件無法避免。 它出於安全原因和默認值。 查看此[SO回答](http://stackoverflow.com/a/32018719/2588459)瞭解更多詳情。 – harkirat1892