简体   繁体   English

关闭浏览器时不会触发onunload

[英]onunload isn't fired when browser closing

Having troubles with onunload, onbeforeunload. onunload,onbeforeunload遇到麻烦。 I need to execute some code when user navigates away from the page, or browser is closed. 当用户离开页面或关闭浏览器时,我需要执行一些代码。 onunload works for navigation away, but doesn't work when browser closes. onunload可用于导航,但在浏览器关闭时不起作用。 I can't use onbeforeunload, since I inject the script into existing website, and it has confirmation upon leaving, so onbeforeunload is fired before user is asked if he wants to leave, so I can't rely on it. 我无法使用onbeforeunload,因为我已将该脚本注入到现有网站中,并且脚本在离开时具有确认,因此在询问用户是否要离开之前会触发onb​​eforeunload,因此我不能依靠它。

What should I do? 我该怎么办?

onbeforeunload would be the event that you would need to use to perform any action before the page closes. onbeforeunload将是您需要在页面关闭之前执行任何操作的事件。 If you can tap into that confirmation box then you can fire your function when they confirm the page closure. 如果您可以点击该确认框,那么当他们确认页面关闭时,您可以启动功能。

Your next best chance is to poll the session serve-side to detect when the user has left the page. 您的下一个最佳机会是轮询会话服务端,以检测用户何时离开页面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM