window.onbeforeunload=function(){ console.log("为啥不能运行");//这个为什么不出现控制台呢? return ; }
window.onbeforeunload=function(e){ e.returnValue = 'something' console.log("为啥不能运行"); return ; }
必须给事件的returnValue属性绑定一个值,否则浏览器会直接关掉,就看不到console的输出了
<body onbeforeunload="return ''"> http://www.runoob.com/jsref/event-onbeforeunload.html
必须给事件的returnValue属性绑定一个值,否则浏览器会直接关掉,就看不到console的输出了