zoukankan      html  css  js  c++  java
  • 检查浏览器

    1.检查当前使用的浏览器
    <script type="text/javascript">
    document.write("名称: " +navigator.appName+"<br>");//浏览器名称
    document.write("版本号: "+navigator.appVersion+"<br>");//浏览器版本号
    document.write("发行代号: "+navigator.appCodeName+"<br>");//浏览器的内部发行代号
    </script>&nbsp;

    2.判断浏览器类型
    <script type="text/javascript">
    var browser=new Object();
    browser.version=parseInt(navigator.appVersion);
    browser.isNetscape=false;
    browser.isMicrosoft=false;

    //用ff打开时,依次返回0 -1
    //用IE打开时,依次返回-1 0
    FF IE
    alert(navigator.appName.indexOf("Netscape")); 0 -1
    alert(navigator.appName.indexOf("Microsoft")); -1 0

    if(navigator.appName.indexOf("Netscape")!=-1)
    { browser.isNetscape=true; document.write("你在使用火狐浏览器"); }
    if(navigator.appName.indexOf("Microsoft")!=-1)
    { browser.isMicrosoft=true; document.write("你在使用微软浏览器"); }
    </script>

    說明:
    navigator就是浏览器对象
    navigator.appName: 浏览器的名称
    indexOf(“Netscape“) 是返回浏览器名称字符串中“Netscape“的位置,如果找不到,则返回-1.
    navigator.appName.indexOf(“Netscape“)!=-1 就是判断句:
    “当前浏览器是Netscape“,如果当前浏览器是Netscape,则返回true,否则返回false

  • 相关阅读:
    五种Sublime text 3同时快速编辑多行内容
    update 更新某个字段自动加1
    oracle 一行记录被锁
    事件
    练习题1
    语法
    开始js
    js简述
    概述
    软连接
  • 原文地址:https://www.cnblogs.com/aure/p/5230820.html
Copyright © 2011-2022 走看看