JS捕获窗口关闭事件
程序员文章站
2022-06-04 07:57:48
...
<script type="text/javascript"> window.onbeforeunload = onbeforeunload_handler; window.onunload = onunload_handler; function onbeforeunload_handler(){ var warning="确认退出?"; return warning; } function onunload_handler(){ var warning="谢谢光临"; alert(warning); } </script> window.onbeforeunload = onbeforeunload_handler; window.onunload = onunload_handler; 这两种都可以捕获窗口关闭事件,window.onbeforeunload 在window.onunload之前执行