简体   繁体   English

当用户试图离开当前页面时,如何显示弹出窗口?

[英]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.

相关问题 当用户尝试离开页面时显示的 Javascript 弹出窗口不会用按钮关闭 - Javascript popup that shows up when user tries to leave page won't close with button 如何阅读Chrome / Firefox弹出动作离开页面时离开/停留? - How to read Chrome/Firefox Pop up actions Leave/Stay when we the leave the page? 如何在 chrome 扩展程序中更新当前活动页面的 url 时删除“离开站点”弹出窗口 - How to remove the ‘leave site ’ pop up While updating the url of the current active page in chrome extension 用户离开页面时如何执行操作 - How to perform action when user leave the page 当用户点击该弹出窗口外的页面上的任何位置时,如何关闭动态添加的弹出窗口? - How to close the dynamically added pop-up when user clicks anywhere on the page outside of that pop-up's surface? 当用户尝试离开我的网页时,创建一个弹出窗口并获取结果 - Create a popup and get results when the user tries to leave my webpage 如何防止IE11弹出(你确定要离开这个页面) - How to prevent IE11 pop up (Are you sure you want to leave this page) 反应,检测用户是否要离开当前页面 - React, Detect if user is going to leave the current page 在浏览器选项卡上显示弹出窗口,关闭或离开页面 - Show pop up on browser tab close or leave the page 当用户到达页面底部时关闭弹出菜单 - Close the pop-up menu when user reach the bottom of the page
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM