有没有办法确定浏览器窗口已关闭? [英] Is there a way to determine that the browser window was closed?

查看:88
本文介绍了有没有办法确定浏览器窗口已关闭?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何识别浏览器的关闭按钮被点击?

How is it possible to identify that the browser's close button was clicked?

推荐答案

来自 JavaScript事件参考,最接近的匹配似乎是OnUnload事件。但是,这也会导致离开页面的导航(因此,如果用户实际点击链接,您不希望这些函数运行。)

From the JavaScript Event Reference, the closest match appears to be the OnUnload event. However, this also catches navigation away from the page (and thus you don't want the functions to run if the user actually clicks on a link.)

没有保证服务器将收到浏览器窗口关闭的消息。例如,大多数现代浏览器都会阻止涉及创建小弹出窗口的旧方法。使用AJAX可能会起作用,但浏览器窗口可能会在尝试连接之前关闭。

There is no guarantee that the server will receive the message that the browser window is closed. For example, the older method that involved creating a small pop-up window would be blocked by most modern browsers. Using AJAX might work, but a browser window may close before it attempts to connect.

这篇关于有没有办法确定浏览器窗口已关闭?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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