zoukankan      html  css  js  c++  java
  • js之判断浏览器类型及版本号

    function browserinfo(){
            
    var Browser_Name=navigator.appName;
            
    var Browser_Version=parseFloat(navigator.appVersion);
            
    var Browser_Agent=navigator.userAgent;
            
            
    var Actual_Version,Actual_Name;
            
            
    var is_IE=(Browser_Name=="Microsoft Internet Explorer");
            
    var is_NN=(Browser_Name=="Netscape");
            
            
    if(is_NN){
                
    //upper 5.0 need to be process,lower 5.0 return directly
                if(Browser_Version>=5.0){
                    
    var Split_Sign=Browser_Agent.lastIndexOf("/");
                    
    var Version=Browser_Agent.indexOf(" ",Split_Sign);
                    
    var Bname=Browser_Agent.lastIndexOf(" ",Split_Sign);

                     Actual_Version
    =Browser_Agent.substring(Split_Sign+1,Version);
                     Actual_Name
    =Browser_Agent.substring(Bname+1,Split_Sign);
                 }
                
    else{
                     Actual_Version
    =Browser_Version;
                     Actual_Name
    =Browser_Name;
                 }
             }
            
    else if(is_IE){
                
    var Version_Start=Browser_Agent.indexOf("MSIE");
                
    var Version_End=Browser_Agent.indexOf(";",Version_Start);
                 Actual_Version
    =Browser_Agent.substring(Version_Start+5,Version_End)
                 Actual_Name
    =Browser_Name;
                
                
    if(Browser_Agent.indexOf("Maxthon")!=-1){
                     Actual_Name
    +="(Maxthon)";
                 }
                
    else if(Browser_Agent.indexOf("Opera")!=-1){
                     Actual_Name
    ="Opera";
                    
    var tempstart=Browser_Agent.indexOf("Opera");
                    
    var tempend=Browser_Agent.length;
                     Actual_Version
    =Browser_Agent.substring(tempstart+6,tempend)
                 }
             }
            
    else{
                 Actual_Name
    ="Unknown Navigator"
                 Actual_Version
    ="Unknown Version"
             }
            
    /*------------------------------------------------------------------------------
             --Your Can Create new properties of navigator(Acutal_Name and Actual_Version) --
             --Userage:                                                                     --
             --1,Call This Function.                                                        --
             --2,use the property Like This:navigator.Actual_Name/navigator.Actual_Version;--
             ------------------------------------------------------------------------------
    */
             navigator.Actual_Name
    =Actual_Name;
             navigator.Actual_Version
    =Actual_Version;
            
            
    /*---------------------------------------------------------------------------
             --Or Made this a Class.                                                     --
             --Userage:                                                                  --
             --1,Create a instance of this object like this:var browser=new browserinfo;--
             --2,user this instance:browser.Version/browser.Name;                        --
             ---------------------------------------------------------------------------
    */
            
    this.Name=Actual_Name;
            
    this.Version=Actual_Version;
         }
         browserinfo();
        
         document.write(
    "你使用的浏览器是:"+navigator.Actual_Name+",版本号:"+navigator.Actual_Version);
  • 相关阅读:
    websocket 心跳及重连
    Liunx下 tomcat自动重启脚本,亲测。
    Node.js 安装配置---菜鸟教程,贼好用
    Linux下安装Perl依赖
    Centos 8 虚拟机访问外网
    以后园子可能用的就比较少了qwq
    酒店之王
    git bash here创建项目时无法使用上下箭头
    Win10搭建IIS实现局域网访问网站
    js判断两个对象是否相同的三种方式
  • 原文地址:https://www.cnblogs.com/di305449473/p/1237491.html
Copyright © 2011-2022 走看看