In front-end development, you often need to determine the browser or system type to solve compatibility issues.
It is easy to use JavaScript to determine the browser and operating system types, but it is not easy to make the most comprehensive and simplest judgment, this article extracts the judgment method from ext 2.2.1, which is the most comprehensive and concise method at present, including the latest IE8, Chrome browser, and air browser judgment. below isCodeAnd contains the following annotations:
VaR UA = navigator. useragent. tolowercase (); VaR Isstrict = Document. compatmode =" Css1compat ", // Whether to define the Document Type Isopera = UA. indexof (" Opera ")>-1, // It is opera Ischrome = UA. indexof (" Chrome ")>-1, // Chrome Issafari =! Ischrome & (/WebKit | khtml/). Test (UA ), // Safari Issafari3 = issafari & UA. indexof (" WebKit/5 ")! =-1, // Safari3 Isie =! Isopera & UA. indexof (" MSIE ")>-1, // IE6 Isie7 =! Isopera & UA. indexof ("MSIE 7 ")>-1, // IE7 Isie8 =! Isopera & UA. indexof (" MSIE 8 ")>-1, // IE8 Isgecko =! Issafari &&! Ischrome & UA. indexof (" Gecko ")>-1, // Gecko Kernel Isgecko3 = isgecko & UA. indexof (" RV: 1.9 ")>-1, // Gecko3 Kernel Isborderbox = isie &&! Isstrict, // Use the Box Model Iswindows = (UA. indexof (" Windows ")! =-1 | UA. indexof (" Win32 ")! =-1 ), // Windows OS Ismac = (UA. indexof (" Macintosh ")! =-1 | UA. indexof (" Mac OS X ")! =-1 ), // MACOs System Isair = (UA. indexof (" Adobeair ")! =-1 ),// Use Adobe AIR to browse Islinux = (UA. indexof (" Linux ")! =-1 ), // It is a Linux System Issecure = Window. Location. href. tolowercase (). indexof (" HTTPS ") = 0; // SSL browsing |