我想显示一个确认弹出窗口,当用户试图离开页面(关闭选项卡)时询问他/她“你想离开页面吗?是否”。当用户单击否时,我想将他/她重定向到特定的 URL。 这是我试过的代码:
$(window).on('beforeunload', function(){
$.Zebra_Dialog('Are you sure to leave the page?', {
'type': 'question',
'title': 'Conformation',
'buttons': ['Yes', 'No'],
});
$("html").on("click",".ZebraDialog_Button_0",function () {
window.location.href = "http://www.google.com/";
});
$("html").on("click",".ZebraDialog_Button_1",function () {
return true;
});
//return false;
});
最佳答案
window.onbeforeunload = onExit;
function onExit() {
return "You have attempted to leave this page. Are you sure?";
}
试试这个,我已经测试了 firefox 和 chrome,它的工作与 safari 无关。
关于javascript - 当用户试图离开当前页面时如何显示弹出窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40131644/