• 判断移动还是PC 以及微信环境


    //判断pc还是移动端

    function IsPC() {

      var userAgentInfo = navigator.userAgent;
      var Agents = ["Android", "iPhone",
            "SymbianOS", "Windows Phone",
            "iPad", "iPod"];
      var flag = true;
      for (var v = 0; v < Agents.length; v++) {
        if (userAgentInfo.indexOf(Agents[v]) > 0) {
          flag = false;
          break;
        }
      }
      return flag;
    }

    // 判断是否是微信

        function isFromWeiXin () {
            var ua = navigator.userAgent.toLowerCase();
            if (ua.match(/MicroMessenger/i) == "micromessenger") {
                return true;
            }
        }
     
    // 检测是否移动端
    if(/iphone|ios|android|mini|mobile|mobi|Nokia|Symbian|iPod|iPad|Windowss+Phone|MQQBrowser|wp7|wp8|UCBrowser7|UCWEB|360s+Aphones+Browser|blackberry/i.test(navigator.userAgent)) {
        location.href = '移动端地址';
    }
    // 检测是否移动端
    if(/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent)) {
        window.location.href = "移动端地址"+location.search;
    }
    //检测是否PC端
    if(!/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent)) {
        window.location.href = "PC端地址"+location.search;
    }

    // 判断 移动环境 PC环境 微信环境
    function judgePcOrAppOrWx() {
    let environment;
    let flag=true;
    let userAgentInfo = navigator.userAgent;
    let userAgentInfoLower = navigator.userAgent.toLowerCase();

    let agents = ['Android', 'iPhone', 'SymbianOS', 'Windows Phone', 'iPad', 'iPod'];
    for (let i = 0; i <agents.length; i++) {
    if (userAgentInfo.indexOf(agents[i]) > -1) {
    flag =false;
    break;

    }
    }

    if (flag === true) {
    environment = 'PC';
    } else if (userAgentInfoLower.match(/MicroMessenger/i) != 'micromessenger') {
    environment = 'APP';
    } else {
    environment = 'WX';
    }
    return environment;
    },
     
  • 相关阅读:
    安装VC6.0遇到的问题
    开发、测试环境
    OPENGL绘制文字
    C++实现文件关联
    MFC多国语言——配置文件
    MFC 资源记录
    如何解决——汉化英文界面出现乱码
    项目配置——添加第三方资源
    队列&生产者消费者模型
    抢票小程序
  • 原文地址:https://www.cnblogs.com/ranyonsue/p/13813881.html
Copyright © 2020-2023  润新知