Determine the browser and operating system type using JavaScript: a comprehensive and concise method

Source: Internet
Author: User

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

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.