Today, the project needs to determine whether the user's behavior is closed or refreshed when leaving the page.
Although there is no direct method, it can be done with certain skills
I have to sigh at the power of JavaScript! !
Please look at the code:
The code copy is as follows:
window.onunload = function(){
var a_n = window.event.screenX - window.screenLeft;
var a_b = a_n > document.documentElement.scrollWidth-20;
if(a_b && window.event.clientY< 0 || window.event.altKey){
alert('Close page behavior');
}else{
alert('Jump or refresh page behavior');
}
}
In fact, it is to detect the window size of the browser at this time by leaving the page behavior time onunload triggering time, and determine whether the user is refreshing, jumping or closing behavior based on the size.
Compatible with major browsers!