JavaScript judges whether the browser is closed or refreshed. In fact, it seems that there is no practicality, even as a reference document for Js learning.
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Title> Js smart judgment on whether the browser is closed or refreshed </title>
<Meta http-equiv = "content-type" content = "text/html; charset = gb2312">
</Head>
<Body>
Close or refresh the browser!
<Script language = "javascript">
Window. onbeforeunload = function (){
Var n = window. event. screenX-window.screenLeft;
Var B = n> document.doc umentElement. scrollWidth-20;
If (B & window. event. clientY <0 | window. event. altKey ){
Alert ("close"); // LieHuo41.Net (LieHuo41.Net): valid only in IE
} Else {
Alert ("refresh ");
}
}
</Script>
</Body>
</Html>