手机访问网站自动跳转到手机版
目前很多网站已经出现了手机版的网站,手机网站是和互联网上的网站同步更新的,大多数人访问我们的网站是直接访问电脑上的域名,不可能为了手机网站重新记住一个域名,大家都知道,中国人都是比较懒的,那么遇到这个情况我们如何面对了,其实办法很简单就是在网站头加入一句判断语句,判断是手机访问网站时就自动跳入手机版,如果是电脑访问就显示正常版本的就可以了。
代码如下:
[code]<script src="http://siteapp.baidu.com/static/webappservice/uaredirect.js" type="text/javascript"></script><script type="text/javascript">uaredirect("你的手机版网址");</script>[/code]
这个是利用百度APP应用,做为一个跳转。
http://jingyan.baidu.com/article/cdddd4 ... 0e198.html
2 判断浏览器来路,自动跳转
[code]<script>
if(navigator.platform.indexOf('Win32')!=-1){
//pc
window.location.href="电脑网址";
}else{
//shouji
window.location.href="手机网址";
}
</script>[/code]
3
[code]<script type="text/javascript">
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= '手机网站地址';
} else {
window.location= '电脑网站地址';
}
}
browserRedirect();
</script>[/code]
4
[code]<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 = '手机网址';
break; } }
</script>[/code]
5 PHP判断跳转
[code]<?php
////这段放手机站里
header("Cache-Control: no-cache");
header("Pragma: no-cache");
$ua = strtolower($_SERVER['HTTP_USER_AGENT']);
$uachar = "/(symbianos|android|Mac OS|ucweb|blackberry)/i";
if($ua != '' && !preg_match($uachar, $ua)){
echo 'window.location.href="电脑地址";';
exit();
}
?>
<?php
//这段放在网站里
header("Cache-Control: no-cache");
header("Pragma: no-cache");
$ua = strtolower($_SERVER['HTTP_USER_AGENT']);
$uachar = "/(symbianos|android|Mac OS|ucweb|blackberry)/i";
if($ua != '' && preg_match($uachar, $ua)){
echo 'window.location.href="手机地址";';
exit();
}
?>[/code]
6PHP判断跳转
[code]<?php
function UserAgent(){
$user_agent = ( !isset($_SERVER['HTTP_USER_AGENT'])) ? FALSE : $_SERVER['HTTP_USER_AGENT'];
return $user_agent;
}
//Mobile
if ((preg_match("/(iphone|ipod|android)/i", strtolower(UserAgent()))) AND strstr(strtolower(UserAgent()), 'webkit')){
header('Location: 手机网址');
exit;
}else if(trim(UserAgent()) == '' OR preg_match("/(nokia|sony|ericsson|mot|htc|samsung|sgh|lg|philips|lenovo|ucweb|opera mobi|windows mobile|blackberry)/i", strtolower(UserAgent()))){
header('Location: 手机网址');
exit;
}else{//PC
header("Location: 电脑网址");
}
?>[/code]