如题,js获取浏览器关闭状态,可实现判断选择是否关闭。
<html> <head> <title> </title> </head> <body> 这是一个页面,点击浏览器关闭触发事件 </body> <script> var name = "张三"; window.onbeforeunload = onbeforeunload_handler; window.onunload = onunload_handler; function onbeforeunload_handler() { var warning = "确认退出?"; return warning; } function onunload_handler() { var warning = "谢谢光临"; alert(warning); } </script> </html>