jQuery 插件: 识别浏览器, 判断浏览器类型和版本, browser detection

项目地址:https://github.com/gabceb/jquery-browser-plugin

CDN下载:https://cdnjs.cloudflare.com/ajax/libs/jquery-browser/0.1.0/jquery.browser.min.js

用法:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-browser/0.1.0/jquery.browser.min.js"></script>

判断 IE ,返回 true 或者 false,支持所有IE浏览器,包括IE 11

$.browser.msie;

判断 WebKit 浏览器 (Safari, Chrome and Opera 15+),返回 true 或者 false

$.browser.webkit;

判断 Firefox 浏览器,返回 true 或者 false

$.browser.mozilla;

读取浏览器版本号

$.browser.version

检查浏览器 arbitrary User-Agents

jQBrowser.uaMatch();

结果如下图:

所以也可以通过 jQBrowser.uaMatch().chrome 来判断是否是chrome浏览器。

其他功能:
  • Detect specifically Windows, Mac, Linux, iPad, iPhone, iPod, Android, Kindle, BlackBerry, Chrome OS, and Windows Phone useragents
    $.browser.android
    	$.browser.blackberry
    	$.browser.cros
    	$.browser.ipad
    	$.browser.iphone
    	$.browser.ipod
    	$.browser.kindle
    	$.browser.linux
    	$.browser.mac
    	$.browser.msedge
    	$.browser.playbook
    	$.browser.silk
    	$.browser.win
    	$.browser["windows phone"]

    Alternatively, you can detect for generic classifications such as desktop or mobile

    $.browser.desktop
    $.browser.mobile
    // User Agent for Firefox on Windows
    User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0
    
    $.browser.desktop // Returns true as a boolean
    // User Agent for Safari on iPhone
    User-Agent: Mozilla/5.0(iPhone; CPU iPhone OS 7_0_3 like Mac OS X; en-us) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11B508 Safari/9537.53
    
    $.browser.mobile // Returns true as a boolean
  • Detect the browser's major version
    // User Agent for Chrome
    // Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1664.3 Safari/537.36
    
    $.browser.versionNumber // Returns 32 as a number
  • Support for new useragent on IE 11
  • Support for Microsoft Edge
  • Support for WebKit based Opera browsers
  • Added testing using PhantomJS and different browser user agents

 

参考:

 

本文:jQuery 插件: 识别浏览器, 判断浏览器类型和版本, browser detection