Section 140th, JavaScript, package library-browser detection

Source: Internet
Author: User

JavaScript, package library-browser detection

Write one in the function library, the browser detects the object

/** SYS Browser detects object with two properties under Object, Liu_lan_qi property and Xi_tong Property * Liu_lan_qi Property, detects browser name and version number, such as: alert (SYS.LIU_LAN_QI); * Xi_tong Property, Detection of browser operating environment, such as: alert (Sys.xi_tong); **/(function() {//closures, self-executingWindow.sys = {};//global variable object, saving browser information    varUA = Navigator.userAgent.toLowerCase ();//get browser information and convert to lowercase    vars = [];//array of browser information    /** Determine IE browser **/    if((/msie ([\d.] +)/). Test (UA)) {//IE10 The following judgment fields: Msie x version numbers = Ua.match (/msie ([\d.] +)/);//returns an array if there is a get to MSIE x version numberSys.liu_lan_qi = ' Browser for ie: ' + s[1];//Add the Liu_lan_qi property to the Sys object, and the property value equals the second element of the obtained array}Else if((/trident/). Test (UA)) {//Ie10 above judgment field: Tridents = Ua.match (/rv: ([\d.] +)/);//returns an array if there is a get to Trident fieldSys.liu_lan_qi = ' Browser for ie: ' + s[1]; }    /** Determine firefox browser **/    if((/firefox\/([\d.] +)/). Test (UA)) {//Firefox judgment field: Firefoxs = Ua.match (/firefox\/([\d.] +)/); Sys.liu_lan_qi= ' Browser for Firefox: ' + s[1]; }    /** Judging Google Browser **/    if((/chrome\/([\d.] +)/). Test (UA)) {//Google judgment field: Chromes = Ua.match (/chrome\/([\d.] +)/); Sys.liu_lan_qi= ' Browser for chrome: ' + s[1]; }    /** Judging Opera browser **/    if((/opera\/.*version\/([\d.] +)/). Test (UA)) {//Google judgment field: Opera and versions = Ua.match (/opera\/.*version\/([\d.] +)/); Sys.liu_lan_qi= ' Browser for opera: ' + s[1]; }    /** Judging Opera browser **/    if((/version\/([\d.] +). *safari/). Test (UA)) {//Google judgment field: Version and Safaris = Ua.match (/version\/([\d.] +). *safari/); Sys.liu_lan_qi= ' Browser for opera: ' + s[1]; }    /** Judging System **/    if(Boolean (navigator.platform)) {Sys.xi_tong= ' Environment system: ' +Navigator.platform; } Else{alert ("Unable to detect environmental system")    }})();

Front desk JS Code

    alert (SYS.LIU_LAN_QI);    alert (Sys.xi_tong);

Section 140th, JavaScript, package library-browser detection

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.