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