onunload在浏览器刷新或关闭时都执行 能不能把刷新和关闭区分开
没搞头,1#给的链接需要打开额外的窗口来监视
/*
::How this works::
1. Checking if an invalid property exist in an object
2. If parent window exist the return will be 'undefined'
3. If parent window does not exist, an exception will be raised which we will catch
4. This exception will tell us that the parent no loger exist thus parent got closed.
Note: this check is run with a 1 sec delay to make sure the window object gets closed properly.
*/
function detectRefresh(){
try
{
if(window.opener.title == undefined){
isRefresh = true;
console.log('Window was refreshed!');
}
}
catch(err)
{
isRefresh = false;
console.log('Window was closed!');
}
}