手机端自适应屏幕跳转到指定的地址

手机端自适应屏幕跳转到指定的地址,js代码(已经测试)和php代码

js代码:
<script type="text/javascript">
var mobileAgent = new Array("iphone", "ipod", "ipad", "android", "mobile", "blackberry", "webos", "incognito", "webmate", "bada", "nokia", "lg", "ucweb", "skyfire");
var browser = navigator.userAgent.toLowerCase();
var isMobile = false;
for (var i=0; i<mobileAgent.length; i++){
 if (browser.indexOf(mobileAgent[i])!=-1){ 
  isMobile = true;//alert(mobileAgent[i]);location.href = 'https://www.qsyidai.com/m';break; 
  } 
}
</script>


php代码:

//设定Mobile的定义
$mobileAgent = array("iphone", "ipod", "ipad", "android", "mobile", "blackberry", "webos", "incognito", "webmate", "bada", "nokia", "lg", "ucweb", "skyfire");
//读取用户的浏览器资料
$browser = $_SERVER['HTTP_USER_AGENT'];
$isMobile = false;
//检查开始
foreach($mobileAgent as $search){
    if(stristr($browser,$search)!=false){
        $isMobile = true;
        //echo $search;
        //程式码(转址)
        header("Location: https://www.qsyidai.com/m");
        //停止运行程序
        exit;
    }
}
?>

  

posted @ 2016-07-14 15:02  镜子-正衣冠-知得失  阅读(436)  评论(0编辑  收藏  举报