zoukankan      html  css  js  c++  java
  • 3种方法判断手机浏览器跳转WAP手机网站

      随着移动设备的普及,企业的网络宣传已经不能局限在PC端,而需要同时在移动端有所建树。对于公司网站来说,以前都是做的PC端的,当然手机等移动端也可以访问,但是用户体验肯定不如完全适合的手机端来的方便。我们在给自己的网站做了WAP手机网站之后,如果有用户通过手机访问我们的企业顶级域名网站,那就判断跳转到专为的手机站点。
      
      第一种:直接JS脚本
      
      <script type="text/javascript">
      
      try {
      
      var urlhash = window.location.hash;
      
      if (!urlhash.match("fromapp"))
      
      {
      
      if ((navigator.userAgent.match(/(iPhone|iPod|Android|ios|iPad)/i)))
      
      {
      
      window.location="http://m.lixincpa.cn(更换成自己的WAP网站)";
      
      }
      
      }
      
      }
      
      catch(err)
      
      {
      
      }</script>
      
      第二种,稍微长一些,引用
      
      function uaredirect(murl){
      
      try {
      
      if(document.getElementById("bdmark") != null){
      
      return;
      
      }
      
      var urlhash = window.location.hash;
      
      if (!urlhash.match("fromapp")){
      
      if ((navigator.userAgent.match(/(iPhone|iPod|Android|ios|iPad)/i))) {
      
      location.replace(murl);
      
      }
      
      }
      
      } catch(err){}
      
      }
      
      上述的脚本保持到mobile.js文件,然后在需要调用的页面引用下面2个JS调用文件。
      
      <script src="mobile.js" type="text/javascript"></script>
      
      <script type="text/javascript">uaredirect("http://m.lixincpa.cn/(更换成自己的WAP网站)");</script>
      
      两种方法都可以使用,我在安卓和IPHONE测试可行。

      下面给大家分享一段php中判断电脑访问还是手机访问的代码:
    <?php
    //手机网页跳转
    //如果检测到访问的浏览器为下列一个指定的移动浏览器 则返回true
    function is_mobile(){
    $regex_match="/(nokia|iphone|android|motorola|^mot-|softbank|foma|docomo|kddi|up.browser|up.link|";
    $regex_match.="htc|dopod|blazer|netfront|helio|hosin|huawei|novarra|CoolPad|webos|techfaith|palmsource|";
    $regex_match.="blackberry|alcatel|amoi|ktouch|nexian|samsung|^sam-|s[cg]h|^lge|ericsson|philips|sagem|wellcom|bunjalloo|maui|";
    $regex_match.="symbian|smartphone|midp|wap|phone|windows ce|iemobile|^spice|^bird|^zte-|longcos|pantech|gionee|^sie-|portalmmm|";
    $regex_match.="jigs browser|hiptop|^ucweb|^benq|haier|^lct|operas*mobi|opera*mini|320x320|240x320|176x220";
    $regex_match.=")/i";
    return isset($_SERVER['HTTP_X_WAP_PROFILE']) or isset($_SERVER['HTTP_PROFILE']) or preg_match($regex_match, strtolower($_SERVER['HTTP_USER_AGENT']));
    }
    $is_mobile=is_mobile();
    if($is_mobile){
    //这是一个手机浏览器,可以跳转到手机版网页
    //header("Location: http://m.lixincpa.cn");
    echo "手机访问";
    }else{
    //这不是一个手机浏览器
    //header("Location: http://www.lixincpa.cn");
    echo "电脑访问";
    }
    ?>

  • 相关阅读:
    IDA Supported Processors
    Hex-Rays Decompiler
    USB ISP(ICSP) Open Programmer < PWM ADC HV PID >
    A SCSI command code -- SIMPLIFIED DIRECT-ACCESS DEVICE (RBC)
    How to match between physical usb device and its drive letter?
    记录一下公司数据库升级的步骤
    Windows2003 SQL2005解决系统Administrator密码不知道的问题
    在SSMS里批量删除表、存储过程等各种对象
    用SQLSERVER里的bcp命令或者bulkinsert命令也可以把dat文件导入数据表
    分享一张SQLSERVER执行流程的图片
  • 原文地址:https://www.cnblogs.com/tanlingdangan/p/4282085.html
Copyright © 2011-2022 走看看