Js Judgment Method for mobile browser operating system and Wechat browser, js judgment

Source: Internet
Author: User

Js Method for Determining the operating system and browser of the mobile browser, js judgment

Today, we will introduce how to use js to determine the mobile client platform and System Platform:

<Script type = "text/javascript"> // determine the function checkPlatform () {if (/android/I. test (navigator. userAgent) {document. write ("This is Android 'browser. "); // This is the Android browser} if (/(iPhoneiPadiPodiOS)/I. test (navigator. userAgent) {document. write ("This is iOS 'browser. "); // This is the browser on the iOS platform} if (/Linux/I. test (navigator. userAgent) {document. write ("This is Linux 'browser. "); // This is a Linux Browser} if (/Linux/I. test (navigator. platform) {document. write ("This is Linux operating system. "); // This is the Linux operating system platform} if (/MicroMessenger/I. test (navigator. userAgent) {document. write ("This is MicroMessenger 'browser. "); // This is a platform browser }}$ (document ). ready (function () {alert (navigator. platform); checkPlatform () ;}); </script>

Note that the above Code uses jquery. Jquery can be run only when it is loaded. Of course, you can delete the trigger function.

Here we will not judge the pc-side operating system platform. Let's talk about how to judge it. For example, we can use document. write (navigator. platform) to obtain the operating system platform. Win32 is displayed under Win32, and Win64 is displayed under Win64.

Below is a small series of helper's house that will provide you with a few good functions.

<Script type = "text/javascript"> var browser = {versions: function () {var u = navigator. userAgent, app = navigator. appVersion; return {trident: u. indexOf ('think')>-1, presto: u. indexOf ('presto ')>-1, webKit: u. indexOf ('applewebkit ')>-1, gecko: u. indexOf ('gecko ')>-1 & u. indexOf ('html ') =-1, mobile :!! U. match (/AppleWebKit. * Mobile. */) | !! U. match (/AppleWebKit/), ios :!! U. match (/\ (I [^;] +; (U ;)? CPU. + Mac OS X/), android: u. indexOf ('android')>-1 | u. indexOf ('linux ')>-1, iPhone: u. indexOf ('iphone ')>-1 | u. indexOf ('mac')>-1, iPad: u. indexOf ('ipad ')>-1, webApp: u. indexOf ('safari ') =-1, QQbrw: u. indexOf ('mqqbrowser ')>-1, weiXin: u. indexOf ('micromessenger ')>-1, ucLowEnd: u. indexOf ('ucweb7. ')>-1, ucSpecial: u. indexOf ('rv: 1.2.3.4 ')>-1, ucweb: function () {try {return parseFloat (u. match (/ucweb \ d + \. \ d +/gi ). toString (). match (/\ d + \. \ d + /). toString ()> = 8.2} catch (e) {if (u. indexOf ('uc')>-1) {return true;} else {return false ;}}(), Symbian: u. indexOf ('symbian ')>-1, ucSB: u. indexOf ('Firefox/1. ')>-1 };}()} if (browser. versions. QQbrw) {document. write ("qq Browser");} else {document. write ("other browsers") ;}</script>

It is very easy to use.

Related Article

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.