javascript控制关闭浏览器的时候,提示信息。

方案一:

<html> 
	<head> 
				<script language="javascript"> 
						window.onbeforeunload = function() //author: meizz 
						{ 
									var n = window.event.screenX - window.screenLeft; 
									var b = n > document.documentElement.scrollWidth-20; 
									if(b && window.event.clientY < 0 || window.event.altKey) 
									{ 
										alert("关闭浏览器!"); 
										window.event.returnvalue = ""; //这里可以放置你想做的操作代码 
									}	
						} 
				</script>
	</head> 
</html> 

 

 

方案二:

<html> 
<head> 
	<title>判断是刷新还是关闭</title> 
</head> 

<script> 
		function CloseOpen(event) { 
					if(event.clientX<=0 && event.clientY<0) { 
							alert("关闭"); 
					} 
					else 
					{ 
							alert("刷新或离开"); 
					} 
		} 
</script> 

<body onunload="CloseOpen(event)"> 
</body> 
</html>

 

你可能感兴趣的:(JavaScript)