js 关闭窗口时操作 onbeforeunload onunload

 

  <script type="text/javascript">   
<!--     
    window.onbeforeunload = onbeforeunload_handler;   
    window.onunload = onunload_handler;
	
    function onbeforeunload_handler(){ 
		//if语句可以减少刷新页面
		if (event.clientX>document.body.clientWidth && event.clientY<0 ||event.altKey){
			 var warning="确认退出?";  
			 alert('onbeforeunload ');
		}
        return warning;   
    }   
       
    function onunload_handler(){   
		alert('onunload' );
        var warning="谢谢光临";   
        alert(warning);   
    }   
// -->   

</script>
 

 

你可能感兴趣的:(JavaScript,onbeforeunload,onunload)