admin管理员组文章数量:1432153
It appears that with the latest release of Chrome (Version 73.0.3683.103 (Official Build) (64-bit)), window onunload event handler isn't being called.
In the latest version of Chrome, my onunload anonymous function seems unreachable.
I'm following MDN Web Docs ().
window.addEventListener('unload', function (e) {
console.log('It worked');
debugger;
});
When I run developer tools in each browser, my snippet of code in Chrome Version 66.0.3359.117, and in Firefox 66.x pauses on the debugger breakpoint as expected when refreshing the window or clicking the back/forward button. Exiting out of the tab, or pletely closing the browser works as expected.
It appears that with the latest release of Chrome (Version 73.0.3683.103 (Official Build) (64-bit)), window onunload event handler isn't being called.
In the latest version of Chrome, my onunload anonymous function seems unreachable.
I'm following MDN Web Docs (https://developer.mozilla/en-US/docs/Web/API/WindowEventHandlers/onunload).
window.addEventListener('unload', function (e) {
console.log('It worked');
debugger;
});
When I run developer tools in each browser, my snippet of code in Chrome Version 66.0.3359.117, and in Firefox 66.x pauses on the debugger breakpoint as expected when refreshing the window or clicking the back/forward button. Exiting out of the tab, or pletely closing the browser works as expected.
https://codepen.io/anon/pen/jRxJxJ
Share Improve this question edited Apr 22, 2019 at 17:01 Kyle Dalan asked Apr 20, 2019 at 0:01 Kyle DalanKyle Dalan 151 silver badge4 bronze badges 3-
It may have to do with the iframe. Putting that code into a top-level
<script>
in the top window performs as expected, at least on Chrome 73.0.3683.86, both on codepen and here on SO – CertainPerformance Commented Apr 20, 2019 at 0:04 -
it does the
console.log
but doesn't stop atdebugger
- I'm actually surprised any browser would stop atdebugger
on unload!! – Jaromanda X Commented Apr 20, 2019 at 1:25 - 1 @CertainPerformance, after I put the code in the top level, or just directly into the console, it works when I close the browser tab. The back, forward, and refresh buttons still don't seem to be reaching the unload hook for me. – Kyle Dalan Commented Apr 22, 2019 at 16:58
1 Answer
Reset to default 3Instead unload, use window.onbeforeunload
for Chrome and it will work fine!
window.onbeforeunload = function (e) {
console.log('It worked');
debugger;
};
Here is the event triggered in Chrome when I close the window.
本文标签: javascriptHow do I get window onunload event trigger to work in Chrome v73xStack Overflow
版权声明:本文标题:javascript - How do I get window onunload event trigger to work in Chrome v73.x? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745589528a2665115.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论