如题所述
æ¹å¼ä¸ï¼ä½¿ç¨JavaScript
<script type="text/javascript">
//设å®Mobileçå®ä¹(å ¨å°å)
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 = 'http://m.lineage.idv.hk/';
//åæ¢è¿è¡åå
break;
}
}
</script>
æ¹å¼äºï¼ä½¿ç¨PHP
<?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: http://m.lineage.idv.hk/");
//åæ¢è¿è¡ç¨åº
exit;
}
}
?>
<script type="text/javascript">
//设å®Mobileçå®ä¹(å ¨å°å)
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 = 'http://m.lineage.idv.hk/';
//åæ¢è¿è¡åå
break;
}
}
</script>
æ¹å¼äºï¼ä½¿ç¨PHP
<?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: http://m.lineage.idv.hk/");
//åæ¢è¿è¡ç¨åº
exit;
}
}
?>
温馨提示:答案为网友推荐,仅供参考
第1个回答 2015-06-09
//通过检测用户ua来识别
if(preg_match('/(blackberry|configuration\/cldc|hp |hp-|htc |htc_|htc-|iemobile|kindle|midp|mmp|motorola|mobile|nokia|opera mini|opera |Googlebot-Mobile|YahooSeeker\/M1A1-R2D2|android|iphone|ipod|mobi|palm|palmos|pocket|portalmmm|ppc;|smartphone|sonyericsson|sqh|spv|symbian|treo|up.browser|up.link|vodafone|windows ce|xda |xda_)/i', $_SERVER['HTTP_USER_AGENT'])){
header('Location: 你的手机版本地址');
}
if(preg_match('/(blackberry|configuration\/cldc|hp |hp-|htc |htc_|htc-|iemobile|kindle|midp|mmp|motorola|mobile|nokia|opera mini|opera |Googlebot-Mobile|YahooSeeker\/M1A1-R2D2|android|iphone|ipod|mobi|palm|palmos|pocket|portalmmm|ppc;|smartphone|sonyericsson|sqh|spv|symbian|treo|up.browser|up.link|vodafone|windows ce|xda |xda_)/i', $_SERVER['HTTP_USER_AGENT'])){
header('Location: 你的手机版本地址');
}