js judgment of the browser window (tab) off and refresh

// set the expiration time localStorage
var beginTime = 0; // start time of execution onbeforeunload
var differTime = 0; // time difference between
the window.onunload = function () {
differTime new new = a Date () the getTime () - beginTime;.
IF ( differTime <=. 5) {
the console.log ( "browser Close");
localStorage.clear ();
} {the else
the console.log ( "browser refresh")
}
};
window.onbeforeunload = function () {
beginTime new new = DATE () the getTime ();.
the console.log (beginTime);
};

 

Address: https://blog.csdn.net/itlsq/article/details/81095323

Guess you like

Origin www.cnblogs.com/YanSmallKind/p/11229555.html