JS to determine the operating system and browser

Source: Internet
Author: User


Our most important work for front-end development is compatibility, system compatibility, browser compatibility, and more. Today I'm going to share a way of judging the operating system and browser that I encapsulated in my project.

Operating system:
varOS = (function() {    varUserAgent =navigator.userAgent.toLowerCase (); return{isipad:/ipad/. Test (useragent), Isiphone:/iphone os/. Test (useragent), isandroid:/android/. Test (useragent), Iswindowsce:/windows ce/. Test (useragent), Iswindowsmobile:/windows mobile/. Test (useragent), Iswin2k:/windows NT 5.0/. Test (useragent), Isxp:/windows NT 5.1/. Test (useragent), Isvista:/windows NT 6.0/. Test (useragent), isWin7:/windows NT 6.1/. Test (useragent), IsWin8:/windows NT 6.2/. Test (useragent), IsWin81:/windows NT 6.3/. Test (UserAgent)};} ());

If you want to determine if the system is an ipad, just determine if (Os.isipad) {}.

var bw = (function () {var useragent = navigator.userAgent.toLowerCase (); return {isuc:/ucweb/.test (useragent),//UC Browser Ischrome:/chrome/.test (Useragent.substr ( -33,6)),/ /Chrome browser Isfirefox:/firefox/.test (useragent),//Firefox Isopera:/opera/.test (useragent),//Opera Browse Device Issafire:/safari/.test (useragent) &&!/chrome/.test (useragent),//Safire browser is360:/360SE /.test (useragent),//360 browser Isbaidu:/bidubrowser/.test (useragent),//Baidu browser Issougou:/metasr/.test (U seragent),//Sogou browser isIE6:/msie 6.0/.test (useragent),//IE6 isIE7:/msie 7.0/.test (useragent),/ /IE7 isIE8:/msie 8.0/.test (useragent),//IE8 isIE9:/msie 9.0/.test (useragent),//IE9 I  SIE10:/msie 10.0/.test (useragent),//IE10 isIE11:/msie 11.0/.test (useragent),//IE11 ISLB: /lbbrowser/.test (useragent)//Cheetah Browser}; ());


I personally test the browser, there may be a problem is the Chrome browser, because most of the browser is using the WebKit kernel, so I cut Chrome navigator to distinguish. If later Chrome's navigator information location or the length of the post-chrome changes will be prone to problems, but it is now possible.

JS to determine the operating system and browser

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.