浏览器窗口关闭

在网上找了N+1久,了解"浏览器窗口关闭"处理。最后用的最多的方法是:

<script language="JavaScript" type="text/JavaScript">    
window.onbeforeunload = onbeforeunload_handler;    
window.onunload = onunload_handler; 

function onunload_handler(){   
	var warning="谢谢光临";   
	alert(warning);   
}    

function onbeforeunload_handler(){   
	var warning = "谢谢光临"; 
	var b = false;    
	var n = window.event.screenX - window.screenLeft;    
	var m = document.documentElement.scrollWidth-20; 
	if(n < m){ 

		b = true; 
	} 
	if(b && window.event.clientY > 0 || window.event.altKey) {    

	warning = &quot;是关闭而非刷新&quot;;    
	//window.event.returnValue = &quot;&quot;; //这里可以放置你想做的操作代码    
	}     
	return warning;   
}     
</script> 

//当然,上面的操作得在IE是必然可行啊,firefox就不能这样了,得把onbeforeunload_handler方法改简单喽: 


function onbeforeunload_handler(){   
	var warning = "谢谢光临"; 
	return warning;   
}     

你可能感兴趣的:(浏览器,IE,firefox)