想在谷歌浏览器关闭时执行一些代码,但是网上的代码基本无效,求指教
毕业设计
1
//这两段代码全能捕获关闭 但是根本不去执行alert,这就失去了捕获的意义了,不过IE就去执行
//jq捕获
$(window).bind("beforeunload",function(){
//TODO 需要执行的代码。
alert(“马上关闭");
return "关闭页面时的提示信息";
});
//js捕获
/* window.onbeforeunload = function (e) {
e = e || window.event;
// For IE and Firefox prior to version 4
if (e) {
e.returnValue = '确定退出吗?';
}
// For Safari
return '确定退出吗?';
}; */
-
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <title>Examples</title> <meta name="description" content=""> <meta name="keywords" content=""> <link href="" rel="stylesheet"> </head> <body> <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> </html>
发表回复