JS - 检查网页是否关闭 [英] JS - Check if a webpage is closed

查看:54
本文介绍了JS - 检查网页是否关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在网页关闭操作上触发一个事件.

I am attempting to fire an event on the action of a webpage closing.

场景是 - 网站打开时有一个单独的窗口,用户可以选择将其最小化.这个最小化的页面然后等待用户关闭,或者在继续执行脚本之前完全离开主页.

The scenario is - a website opens with a separate window, which the user may choose to minimize. This minimized page then waits for the user to either close, or navigate away entirely from the main page before proceeding with a script.

我查看了 jQuery unload() 方法,但我认为它不够具体,即它会触发任何类型的导航(刷新、菜单导航等)

I have looked at the jQuery unload() method, but I don't think it's specific enough i.e. it fires on any kind of navigation (refresh, menu nav etc.)

是否可以使用此方法或其他方法来实现此操作?

Is it possible to use this, or another method to achieve this action?

推荐答案

好吧,这是不可能的,因为没有 WINDOW_CLOSED 事件,因为显示为浏览器主窗口的窗口对象属于底层操作系统的权限.即使在 TDI(选项卡式文档接口)的情况下,如在浏览器中实现的 Microsoft 的 MDI,也不会在关闭选项卡时触发任何事件.

Well, this is just not possible as there is no WINDOW_CLOSED event because window objects displayed like main window of a browser fall under the rights of the underlying OS. Even in cases where TDI( Tabbed Documents Interface ), like Microsoft's MDI is implemented in the browsers, no event is fired upon closing of a tab.

这篇关于JS - 检查网页是否关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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