Js/jquery determine browser name, kernel version, browser shell

Source: Internet
Author: User

1. js Method/*judging the browser name and version can only be judged: ie/firefox/chrome/opera/safari2012 May 16 23:47:08 browser kernel ua:ua; browser kernel name: nv.name; browser kernel version: nv.version; browser shell name: Nv.shell;*/varNV = {};varUA =navigator.userAgent.toLowerCase ();Try{nv.name=!-[1,]? ' ie:(Ua.indexof ("Firefox") >0)? ' Firefox:(Ua.indexof ("Chrome") >0)? ' Chrome: Window.opera?‘ Opera: Window.opendatabase?‘ Safari:' Unkonw ';}Catch(e) {};Try{nv.version= (nv.name== ' IE ')? Ua.match (/msie ([\d.] +)/) [1]:(Nv.name= = ' Firefox ')? Ua.match (/firefox\/([\d.] +)/) [1]:(Nv.name= = ' Chrome ')? Ua.match (/chrome\/([\d.] +)/) [1]:(Nv.name= = ' opera ')? Ua.match (/opera. ( [\d.] +)/) [1]:(Nv.name= = ' Safari ')? Ua.match (/version\/([\d.] +)/) [1]:' 0 ';}Catch(e) {};Try{Nv.shell= (Ua.indexof (' 360ee ') >-1)? ' 360 Speed Browser ':(Ua.indexof (' 360SE ') >-1)? ' 360 Secure Browser ':(Ua.indexof (' SE ') >-1)? ' Sogou Browser ':(Ua.indexof (' Aoyou ') >-1)? ' Surfing the browser ':(Ua.indexof (' TheWorld ') >-1)? ' window of the World browser ':(Ua.indexof (' Worldchrome ') >-1)? ' window of the World Speed Browser ':(Ua.indexof (' Greenbrowser ') >-1)? ' Green Browser ':(Ua.indexof (' Qqbrowser ') >-1)? ' QQ Browser ':(Ua.indexof (' Baidu ') >-1)? ' Baidu Browser ':' Unknown or no shell ';}Catch(e) {}alert (' Browser ua= ' +ua+ ' \ n \ nthe browser name = ' +nv.name+ ' \ n ' browser version = ' +parseint (nv.version) + ' \ n ' Browser shell = ' +Nv.shell);});2. jquery plugin; (function($){/*judging the browser name and version can only be judged: ie/firefox/chrome/opera/safari2012 May 16 23:47:08 The browser kernel is ua:$. NV (' UA '), or $. NV (' UA '); browser kernel name: $. NV (' name '), or $. NV (); browser kernel version: $. NV (' version '); browser shell name: $. NV (' shell ');*/$.extend ({NV:function(name) {varNV = {};varUA =navigator.userAgent.toLowerCase ();Try{nv.name=!-[1,]? ' ie:(Ua.indexof ("Firefox") >0)? ' Firefox:(Ua.indexof ("Chrome") >0)? ' Chrome: Window.opera?‘ Opera: Window.opendatabase?‘ Safari:' Unkonw ';}Catch(e) {};Try{nv.version= (nv.name== ' IE ')? Ua.match (/msie ([\d.] +)/) [1]:(Nv.name= = ' Firefox ')? Ua.match (/firefox\/([\d.] +)/) [1]:(Nv.name= = ' Chrome ')? Ua.match (/chrome\/([\d.] +)/) [1]:(Nv.name= = ' opera ')? Ua.match (/opera. ( [\d.] +)/) [1]:(Nv.name= = ' Safari ')? Ua.match (/version\/([\d.] +)/) [1]:' 0 ';}Catch(e) {};Try{Nv.shell= (Ua.indexof (' 360ee ') >-1)? ' 360 Speed Browser ':(Ua.indexof (' 360SE ') >-1)? ' 360 Secure Browser ':(Ua.indexof (' SE ') >-1)? ' Sogou Browser ':(Ua.indexof (' Aoyou ') >-1)? ' Surfing the browser ':(Ua.indexof (' TheWorld ') >-1)? ' window of the World browser ':(Ua.indexof (' Worldchrome ') >-1)? ' window of the World Speed Browser ':(Ua.indexof (' Greenbrowser ') >-1)? ' Green Browser ':(Ua.indexof (' Qqbrowser ') >-1)? ' QQ Browser ':(Ua.indexof (' Baidu ') >-1)? ' Baidu Browser ':' Unknown or no shell ';}Catch(e) {}Switch(name) { Case' UA ': Case' UA ': br=ua; Break; Case' Name ': br=nv.name; Break; Case' Version ': br=nv.version; Break; Case' Shell ': br=nv.shell; Break;default: br=Nv.name;}return( BR;});}) (jQuery); Call method (must load this plug-in): $ (function() {alert (' Browser ua= ' +$. NV (' UA ') + ' \ n \ nthe browser name = ' +$. NV (' name ') + ' \ n \ nthe browser version = ' +parseint ($. NV (' version ')) + ' \ n \ nthe browser shell = ' +$. NV (' Shell '));}); This is basically complete. 

Js/jquery determine browser name, kernel version, browser shell

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.