在浏览器窗口/选项卡上打开自定义弹出窗口关闭 [英] open a custom popup on browser window/tab close

查看:316
本文介绍了在浏览器窗口/选项卡上打开自定义弹出窗口关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在浏览器窗口/选项卡上打开自定义弹出窗口。

I am trying to open a custom popup on browser window/tab close.

详细说明如果用户点击浏览器窗口/选项卡关闭按钮,会出现带有某些内容的自定义弹出窗口,或者可能有某些选项要求关闭或继续该页面。

In details if a user clicks on the browser window/tab close button a custom popup will appear with some content or may be having some option asking to close or continue the page.

这里是只带来默认警报弹出窗口的代码:

here is the code which only bring the default alert popup:

window.onbeforeunload = function() {
              var message = 'Do you want to leave this page?';
              return message;
          }


推荐答案

我也建议你不要这样做,但毕竟,你问了一个问题并得到答案。

i would also suggest you dont do this, but after all, you asked a question and deserve an answer.

<script type="text/javascript">
     var popit = true;
     window.onbeforeunload = function() { 
          if(popit == true) {
               popit = false;
               return "Are you sure you want to leave?"; 
          }
     }
</script>

此脚本可以使用( http://jsfiddle.net/SQAmG/3/
并确保它只会弹出一次(如果他决定不再打扰用户)留一次)。

this script will work (http://jsfiddle.net/SQAmG/3/) and will make sure that it will only popup once (to not bother the user again if he decided to stay once).

这篇关于在浏览器窗口/选项卡上打开自定义弹出窗口关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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