zoukankan      html  css  js  c++  java
  • js判断手机浏览器操作系统和微信浏览器的方法

    做手机端的前端开发,少不了对手机平台的判断。如,对于app下载,就要判断在Android平台下就显示Android下载提示;在iOS平台下就显示iOS下载提示。

    今天就为大家介绍一下用js判断手机客户端平台及系统平台的方法:

    01
    02
    03
    04
    05
    06
    07
    08
    09
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    <script type="text/javascript">
    //手机端判断各个平台浏览器及操作系统平台
    function checkPlatform(){
      if(/android/i.test(navigator.userAgent)){
          document.write("This is Android'browser.");//这是Android平台下浏览器
      }
      if(/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)){
          document.write("This is iOS'browser.");//这是iOS平台下浏览器
      }
      if(/Linux/i.test(navigator.userAgent)){
          document.write("This is Linux'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'browser.");//这是微信平台下浏览器
      }
    }
      $(document).ready(function(){
        alert(navigator.platform);
        checkPlatform();
      });
    </script>

    在这里就不做pc端操作系统平台的判断了,怎么判断也说下方法,如用document.write(navigator.platform);就可以获得操作系统平台。在win32下就会显示Win32,;在Win64下就会显示Win64等。

  • 相关阅读:
    【0711作业】使用封装实现企鹅
    【0711作业】模拟选民投票
    【0709作业】判断三个数是否能组成三角形以及组成的三角形类型
    【0709作业】简易的购房商贷月供计算器
    【0708】(OOP)用户密码管理
    数据库基础
    转行小白成长路-java篇
    转行小白成长路-java篇
    转行小白成长路-java篇
    转行小白成长路-java篇
  • 原文地址:https://www.cnblogs.com/dxqNet/p/6515119.html
Copyright © 2011-2022 走看看