zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    复利计算-做汉堡,结对2.0
    复利计算-结对
    《构建之法》第四章读后感
    复利计算单元测试
    实验一 命令解释程序的编写
    《构建之法》前三章章读后感
    1.0 2.0 3.0复利计算器
    实验0:了解和熟悉操作系统
    学习进度条
    0302思考并回答一些问题
  • 原文地址:https://www.cnblogs.com/liruning/p/6405815.html
Copyright © 2011-2022 走看看