zoukankan      html  css  js  c++  java
  • 判断设备,跳转到移动端和PC端

    移动端页面写法

    function browserRedirect() {
      var sUserAgent = navigator.userAgent.toLowerCase();
      var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
      var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
      var bIsMidp = sUserAgent.match(/midp/i) == "midp";
      var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
      var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
      var bIsAndroid = sUserAgent.match(/android/i) == "android";
      var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
      var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
      if (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) {
      } else {
        window.location.href="index.html";
        //跳转到pc端对应页面
      }
    }
    
    browserRedirect();
    

    PC端页面写法

    function browserRedirect() {
      var sUserAgent = navigator.userAgent.toLowerCase();
      var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
      var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
      var bIsMidp = sUserAgent.match(/midp/i) == "midp";
      var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
      var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
      var bIsAndroid = sUserAgent.match(/android/i) == "android";
      var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
      var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
      if(bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) {
      	window.location.href = "m_index.html";
      	//跳转到移动端对应页面
      } else {
    
      }
    }
    
    browserRedirect();
    
  • 相关阅读:
    Linux系统中常用操作命令
    CentOS 7 巨大变动之 systemd 取代 SysV的Init
    不可不知的安卓屏幕知识
    Gradle-jar-aar
    【Android】开源项目汇总
    Android中关于系统Dialog无法全屏的问题(dialog样式)
    Android LockScreen (锁屏弹窗)
    linux 权限设置
    android 多语言(在APP里面内切换语言)
    host更新
  • 原文地址:https://www.cnblogs.com/njuclc/p/12897400.html
Copyright © 2011-2022 走看看