首页 > 代码库 > 浏览器简易嗅探器

浏览器简易嗅探器

document.write(navigator.userAgent);document.write(‘<br/>‘);document.write(navigator.platform);var client = function(){//引擎    var engine = {        ie:false,        gecko:false,        khtml:false,        opera:false,        webkit:false,        ver:0    };//浏览器    var browser = {        ie:false,        firefox:false,        chrome:false,        safari:false,        opera:false,        ver:0,        name:‘‘    };//系统    var system = {        win:false,        mac:false,        x11:false,        sysname:‘‘    }//核心监测程序    var ua = navigator.userAgent;    var p = navigator.platform;    if(p.indexOf(‘Win‘) == 0){        system.win = true;        system.sysname = ‘Window‘;    }else if(p.indexOf(‘Mac‘) == 0){        system.mac = true;        system.sysname = ‘Macintosh‘;    }else if(p == ‘X11‘ || p.indexOf(‘Linux‘) == 0){        system.x11 = true;        system.sysname = ‘Linux‘;    }    if(window.opera){        engine.opera = true;        engine.ver= browser.ver = window.opera.version();        engine.name= ‘Opera‘;    }else if(/AppleWebKit\/(\S+)/.test(ua)){        engine.webkit = true;        engine.ver = RegExp[‘$1‘];        if(/Chrome\/(\S+)/.test(ua)){            browser.chrome = true;            browser.ver = RegExp[‘$1‘];            browser.name = ‘Chrome‘;        }else{            borwser.safari = true;            if(/Version\/(\S+)/.test(ua)){                browser.ver = RegExp[‘$1‘];                browser.name = ‘safari‘;            }        }    }else if(/rv:([^\)]+)\) Gecko\/\d{8}/.test(ua)){        engine.gecko = true;        engine.ver = RegExp[‘$1‘];        if(/Firefox\/(\S+)/.test(ua)){            browser.firefox = true;            browser.ver = RegExp[‘$1‘];            browser.name = ‘Firefox‘;        }    }else if(/MSIE ([^;]+)/.test(ua)){        engine.ie = browser.ie = true;        engine.ver = browser.ver = RegExp[‘$1‘];        browser.name = ‘Internet Explorer‘;    }    return {        engine:engine,        browser:browser,        system:system    }}();alert(client.system.sysname + "目前使用的是" + client.browser.name + "浏览器,版本为" + client.browser.ver);