[英]How to display a pop up, when a user tries to leave the current page?
I want to display a conformation pop up, when user tries to leave the page (close the tab) asking him/her "You want to leave the page? Yes No". 当用户试图离开页面(关闭标签页)时,我想显示一个确认弹出窗口,询问他/她“你想要离开页面吗?是否”。 When the user click the NO, I want to redirect him/her to a specific URL.
当用户单击否时,我想将他/她重定向到特定的URL。 Here is the code I have tried:
这是我尝试过的代码:
$(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?";
}
Try this, i have tested firefox and chrome its working not idea about safari. 试试这个,我测试了firefox和chrome它的工作不知道safari。
Jquery script Jquery脚本
<script type="text/javascript">
$('#reload').click(function() {
location.reload();
});
$(window).bind('beforeunload', function(){
return 'Are you sure to leave the page?';
});
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.