检测浏览器关闭事件时如何显示自定义弹出窗口? [英] How to show custom pop up when detect browser close event?

查看:459
本文介绍了检测浏览器关闭事件时如何显示自定义弹出窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Google Chrome浏览器中查找窗口/标签关闭事件. 在goole chrome中,unload()无法正常工作. 所以我用

I am trying to find window/tab close event in Google Chrome. In goole chrome, unload() is not working. So i used

<body onbeforeunload="return OnBeforeUnLoad ()">

javascript代码:

javascript Code :

function OnBeforeUnLoad() {
    return "Your tutorial will be finished unexpectedly";
} 

在Chrome中运行正常.但这会抛出chrome的默认弹出窗口.我想要我自己的弹出框.

It is working fine in Chrome. But it throws default pop up of chrome. I want my own pop up box.

那我该怎么办呢?

推荐答案

您不能.想象一个广告商添加了代码以在关闭窗口时显示弹出广告,或者是一个骗子添加了具有确定"和取消"反转或不起作用的弹出窗口;可以追溯到互联网的旧时代,当时浏览器过于信任,用户有时需要强制退出浏览器以逃脱页面.

You cannot. Imagine an advertiser adding code to display a popup advert when the window is closed, or a trickster adding a popup which has "OK" and "Cancel" reversed or non-functional; it's back to the old days of the internet when browsers were too trusting and users were left occasionally needing to force-quit the browser just to escape a page.

为防止出现这种情况,最近这些网站被允许在标准弹出窗口中显示文本块.您没有比这更多的控制权了.

To prevent it, these days sites are allowed to display a block of text within a standard popup. You have no more control than that.

我能提供的最好证明是:去在线电子邮件提供商处,在上传内容时关闭窗口,或者在编辑内容后jsfiddle并关闭窗口,或者在任何没有自动保存功能即可编辑内容的主要网站上.请注意,它们使用浏览器标准的弹出窗口.如果有其他选择,则其中一个会使用它.

The best proof I can offer is this: go to an online email provider and close the window while uploading something, or jsfiddle and close the window after editing something, or any major site where you can edit things without an autosave. Notice that they use the browser-standard popup. If there were an alternative, one of them would have used it.

这篇关于检测浏览器关闭事件时如何显示自定义弹出窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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