js判断是哪种浏览器和阻止页面加载

 1 <html>
 2     <head>
 3     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
 4     </head>
 5     <body>
 6     <script type = "text/javascript">
 7         window.onload = function()
 8         {
 9             //页面加载判断是哪种浏览器
10             function getOs() 
11             { 
12                 var OsObject = ""; 
13                if(navigator.userAgent.indexOf("MSIE")>0) { 
14                     return "MSIE"; 
15                } 
16                else if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){ 
17                     return "Firefox"; 
18                } 
19                else if(isMozilla=navigator.userAgent.indexOf("Opera")>0){ 
20                     return "Opera"; 
21                } 
22                else if(isFirefox=navigator.userAgent.indexOf("Chrome")>0){ 
23                     return "Chrome"; 
24                } 
25                else if(isSafari=navigator.userAgent.indexOf("Safari")>0) { 
26                     return "Safari"; 
27                }  
28                else if(isCamino=navigator.userAgent.indexOf("Camino")>0){ 
29                     return "Camino"; 
30                } 
31                else if(isMozilla=navigator.userAgent.indexOf("Gecko/")>0){ 
32                     return "Gecko"; 
33                }
34                
35             } 
36             alert("您的浏览器类型为:"+getOs());
37             
38             /* //js停止(阻止)浏览器继续加载内容
39             function CloseSearch() {
40                 $("#searchEffect").html(searchEffect);
41                 var xmlhttp;
42                 if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
43                     xmlhttp = new XMLHttpRequest();
44                 }
45                 else {// code for IE6, IE5
46                     xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
47                 }
48                 xmlhttp.abort();
49                 mystop();
50                 //alert("dddd");
51             }
52 
53             function mystop() {
54                 if (!!(window.attachEvent && !window.opera)){ 
55                     document.execCommand("stop"); 
56                 }
57                 else{ 
58                     window.stop(); 
59                 }
60             }
61             */
62         }
63     </script>
64     </body>
65 </html>

 

posted @ 2017-02-16 15:07  今天、天气晴  阅读(2073)  评论(0编辑  收藏  举报