关闭浏览器弹出新窗口

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
 
  
  	     function getOs(){
          if(navigator.userAgent.indexOf("MSIE")>0)return 1;//IE
          if(isFirefox=navigator.userAgent.indexOf("Firefox")>0)return 2;//Firefox
		  if(isSafari=navigator.userAgent.indexOf("Chrome")>0)return 3;//Chrome
          if(isSafari=navigator.userAgent.indexOf("Safari")>0)return 4;//Safari
          if(isCamino=navigator.userAgent.indexOf("Camino")>0)return 5;//Camino
          if(isMozilla=navigator.userAgent.indexOf("Gecko/")>0)return 6;//Gecko
		  if(isOpera=navigator.userAgent.indexOf('Opera') >= 0) return 7;//Opera
           //other...
          return 0;
          }
	     
	     var quite=false;
		 
		 		 
		 function bindOnbeforeunload(){
			
		    quite=false;
		    window.onbeforeunload=checkLeave;
		 }
	     
		 function unbindOnbeforeunload(){
		     quite=true;
			 window.onbeforeunload=null;
			 window.open("http://www.baidu.com","sdfsdf");
		 }
		 
		 
		 
      function checkLeave(){				
			  //alert(111111111);
			  //return window.open("http://www.baidu.com");
			 return '您正在离开...';		
        }
	
 
	  window.onunload=function(){
	          try{
	            unbindOnbeforeunload();
              }catch(e){
			  
			  }
				window.location.href='http://www.baidu.com';				 
			    if(getOs()==3||getOs()==4){
				    var xmlHttp = false;
				try {
					xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
				} catch (e) {
					try {
						xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
					} catch (e2) {
						xmlHttp = false;
					}
				}
				if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
	            xmlHttp = new XMLHttpRequest();
				}
				var url = "http://www.baidu.com";
				xmlHttp.open("POST", url, false);
				// Send the request
				xmlHttp.send(null);
				   window.open('', '_self', ''); //bug fix
                   window.close();
				} 
	  }
	  
	 
	 
	</script>
	</head>

	
</script>
</head>

<body oncontextmenu="return false;"  onload="javascript:return bindOnbeforeunload();" >
</body>
</html>

 

posted @ 2013-11-01 13:17  haiwei.sun  阅读(192)  评论(0)    收藏  举报
返回顶部