Today, because the project needs to determine whether the user’s behavior is to close or refresh when leaving the page
Although there is no direct method, it can be done with certain techniques
I have to lament the power of JavaScript! !
Please take a look at the code:
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 browser window size at this time through the onunload trigger time of leaving the page behavior time, and based on the size, it can be judged whether the user refreshes, jumps or closes the behavior.
Compatible with all major browsers!
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn