zoukankan      html  css  js  c++  java
  • js判断是否手机端,相对域名跳转到对应的m.手机站

    js判断是否手机端,相对域名跳转到对应的m.手机站

    <script type="text/javascript">(function(Switch) {
        var switch_pc = window.location.hash;
        var curURL = document.location.href; //当前URL
        var isMobile = curURL.indexOf("http://m."); //判断当前URL是否是手机站
        var isPc = curURL.indexOf("http://www."); //判断当前URL是否包含"http://www."
        if (isMobile < 0) { //不是手机站
            if (isPc < 0) { //不包含"http://www."
            var thisURL = curURL.replace(/^http:///, "http://m.");
        } else { // 包含"http://www."
            var thisURL = curURL.replace(/^http://www./, "http://m.");
        }
      }
      if (switch_pc != "#pc") {
        if (/iphone|ipod|ipad|ipad|Android|nokia|blackberry|webos|webos|webmate|bada|lg|ucweb|skyfire|sony|ericsson|mot|samsung|sgh|lg|philips|panasonic|alcatel|lenovo|cldc|midp|wap|mobile/i.test(navigator.userAgent.toLowerCase())) {
          Switch.location.href = thisURL;
        }
        document.write('<meta name="mobile-agent" content="format=html5;url=' + thisURL + '" />');
      }
    })(window);
    </script>
    转载请注明出处: 欢迎留言或qq(1090413588)交流
  • 相关阅读:
    树莓派GPIO点亮第一个led
    hexo博客域名重复提交问题
    python与arduino串口通讯对接opencv实现智能物品分拣
    python生成excel文件
    python的机器学习之路
    团队冲刺第三天
    团队冲刺第二天
    团队冲刺第一天
    第二阶段任务认领
    构建之法3
  • 原文地址:https://www.cnblogs.com/linyusong/p/6420063.html
Copyright © 2011-2022 走看看