用户尝试离开当前页面时如何显示弹出窗口? [英] How to display a pop up, when a user tries to leave the current page?

查看:84
本文介绍了用户尝试离开当前页面时如何显示弹出窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户尝试离开页面(关闭选项卡)并询问他/她您要离开页面吗?是,否"时,我想显示一个弹出的构型.当用户单击否"时,我想将他/她重定向到特定的URL. 这是我尝试过的代码:

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. 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?";
    }

尝试一下,我已经测试了firefox和chrome的工作原理,而不是关于野生动物园的想法.

Try this, i have tested firefox and chrome its working not idea about safari.

这篇关于用户尝试离开当前页面时如何显示弹出窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆