JS Get browser kernel

Source: Internet
Author: User


<script language= "JavaScript" type= "Text/javascript" >varBrowser ={versions:function () { varU = navigator.useragent, app =navigator.appversion; return{//Mobile Terminal browser version informationTrident:u.indexof (' Trident ') >-1,//IE kernelPresto:u.indexof (' presto ') >-1,//Opera KernelWebkit:u.indexof (' AppleWebKit ') >-1,//Apple, Google kernelGecko:u.indexof (' Gecko ') >-1 && u.indexof (' khtml ') = =-1,//Firefox kernelMobile:!! U.match (/applewebkit.*mobile.*/) | | !! U.match (/applewebkit/),//whether it is a mobile terminalIos:!! U.match (/\ (i[^;] +;( U;)? Cpu.+mac OS x/),//iOS terminalAndroid:u.indexof (' Android ') >-1 | | U.indexof (' Linux ') >-1,//Android Terminal or UC browserIphone:u.indexof (' IPhone ') >-1 | | U.indexof (' Mac ') >-1,//whether it's an iphone or Qqhd browserIpad:u.indexof (' IPad ') >-1,//whether ipadWebapp:u.indexof (' Safari ') = =-1//whether the web should program, no head with the bottom }; } (), Language: (Navigator.browserlanguage||navigator.language). toLowerCase ()} Document.writeln ("Language version:" +browser.language); Document.writeln ("Whether it is a mobile terminal:" +browser.versions.mobile); Document.writeln ("iOS Terminal:" +Browser.versions.ios); Document.writeln ("Android Terminal:" +browser.versions.android); Document.writeln ("Is the iphone:" +Browser.versions.iPhone); Document.writeln ("Whether ipad:" +Browser.versions.iPad); Document.writeln (navigator.useragent);</script>
//Another type of://the implementation functions are as followsfunctionGetbrowser (n) {varUA =Navigator.userAgent.toLowerCase (), S, name= ' ', ver= 0; //Probe Browser(s = Ua.match (/msie ([\d.] +)/)) ? _set ("ie", _tofixedversion (s[1]): (S= Ua.match (/firefox\/([\d.] +)/)) ? _set ("Firefox", _tofixedversion (s[1]): (S= Ua.match (/chrome\/([\d.] +)/)) ? _set ("Chrome", _tofixedversion (s[1]): (S= Ua.match (/opera. ( [\d.] +)/)) ? _set ("Opera", _tofixedversion (s[1]): (S= Ua.match (/version\/([\d.] +). *safari/))? _set ("Safari", _tofixedversion (s[1)): 0; function_tofixedversion (ver, floatlength) {ver= (' + ver '). Replace (/_/g, '. ')); Floatlength= Floatlength | | 1; Ver= String (ver). Split ('. ')); Ver= ver[0] + '. ' + (Ver[1] | | ' 0 '); Ver=Number (ver). toFixed (Floatlength); returnver; }  function_set (bname, bver) {name=bname; Ver=Bver; }  return(n = = ' n '? Name: (n = = ' V '? Ver:name +ver));}; When called,varNeihe = Getbrowser ("n"); What you get is the kernel used by the browser. When calledvarBanben = Getbrowser ("V"); What you get is the version number of the browser. When calledvarBrowser = Getbrowser (); What you get is the browser kernel plus the version number.

JS Get browser kernel

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.