Summary:
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) {}.
Browser:
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}; ());
Summary:
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