Home > Web Front-end > JS Tutorial > body text

js method to determine mobile browser operating system and WeChat browser_javascript skills

PHP中文网
Release: 2016-05-16 15:02:56
Original
2093 people have browsed it

Today I will introduce to you how to use js to determine the mobile client platform and system platform:

<script type="text/javascript">
//手机端判断各个平台浏览器及操作系统平台
function checkPlatform(){
    if(/android/i.test(navigator.userAgent)){
        document.write("This is Android&#39;browser.");//这是Android平台下浏览器
    }
    if(/(iPhoneiPadiPodiOS)/i.test(navigator.userAgent)){
        document.write("This is iOS&#39;browser.");//这是iOS平台下浏览器
    }
    if(/Linux/i.test(navigator.userAgent)){
        document.write("This is Linux&#39;browser.");//这是Linux平台下浏览器
    }
    if(/Linux/i.test(navigator.platform)){
        document.write("This is Linux operating system.");//这是Linux操作系统平台
    }
    if(/MicroMessenger/i.test(navigator.userAgent)){
        document.write("This is MicroMessenger&#39;browser.");//这是微信平台下浏览器
    }
}
 $(document).ready(function(){
  alert(navigator.platform);
  checkPlatform();
 });
</script>
Copy after login

Note that the above code uses jquery. jquery needs to be loaded to run. Of course, you can delete the trigger function

I won’t judge the PC operating system platform here. How to judge is also explained. For example, use document.write(navigator.platform); to get it. operating system platform. Under win32, Win32 will be displayed; under Win64, Win64, etc. will be displayed.

<script type="text/javascript">
var browser = {
    versions : function () {
        var u = navigator.userAgent,
        app = navigator.appVersion;
        return {
            trident : u.indexOf(&#39;Trident&#39;) > -1,
            presto : u.indexOf(&#39;Presto&#39;) > -1,
            webKit : u.indexOf(&#39;AppleWebKit&#39;) > -1,
            gecko : u.indexOf(&#39;Gecko&#39;) > -1 && u.indexOf(&#39;KHTML&#39;) == -1,
            mobile : !!u.match(/AppleWebKit.*Mobile.*/) || !!u.match(/AppleWebKit/),
            ios : !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/),
            android : u.indexOf(&#39;Android&#39;) > -1 || u.indexOf(&#39;Linux&#39;) > -1,
            iPhone : u.indexOf(&#39;iPhone&#39;) > -1 || u.indexOf(&#39;Mac&#39;) > -1,
            iPad : u.indexOf(&#39;iPad&#39;) > -1,
            webApp : u.indexOf(&#39;Safari&#39;) == -1,
            QQbrw : u.indexOf(&#39;MQQBrowser&#39;) > -1,
            weiXin : u.indexOf(&#39;MicroMessenger&#39;) > -1,
            ucLowEnd : u.indexOf(&#39;UCWEB7.&#39;) > -1,
            ucSpecial : u.indexOf(&#39;rv:1.2.3.4&#39;) > -1,
            ucweb : function () {
                try {
   return parseFloat(u.match(/ucweb\d+\.\d+/gi).toString().match(/\d+\.\d+/).toString()) >= 8.2
                } catch (e) {
                    if (u.indexOf(&#39;UC&#39;) > -1) {
                        return true;
                    } else {
                        return false;
                    }
                }
            }
            (),
            Symbian : u.indexOf(&#39;Symbian&#39;) > -1,
            ucSB : u.indexOf(&#39;Firefox/1.&#39;) > -1
        };
    }
    ()
}
if (browser.versions.QQbrw){
document.write("qq浏览器");
}else
{
document.write("其它浏览器");
}
</script>
Copy after login


The above is the method of js to judge the mobile browser operating system and WeChat browser_javascript skills. For more related content, please Follow the PHP Chinese website (www.php.cn)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template