第一种:使用百度出品的uaredirect.js来判断客户端是否为手机
<script src="http://www.wuhannews.cn/js-bak/uaredirect-baidu.js" type="text/javascript"></script><script type="text/javascript">uaredirect("http://www.wuhannews.cn/m");</script>
第二种:进入网站自动跳转
<meta http-equiv="refresh" content="0;url= /m ">
第三种:
<script type="text/javascript">
var commonURL = 'http://www.wuhannews.cn/';
function mobile_device_detect(url){
var thisOS=navigator.platform;
var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");
for(var i=0;i<os.length;i++){
if(thisOS.match(os[i])){
window.location=url;
}
}
if(navigator.platform.indexOf('iPad') != -1){
window.location=url;
}
var check = navigator.appVersion;
if( check.match(/linux/i) ){
if(check.match(/mobile/i) || check.match(/X11/i)) {
window.location=url;
}
}
Array.prototype.in_array = function(e){
for(i=0;i<this.length;i++){
if(this[i] == e)
return true;
}
return false;
}
}
mobile_device_detect("http://www.wuhannews.cn//m");/*指定跳转地址*/
</script>
第四种:
<script type="text/javascript">
(function(Switch){var switch_pc = window.location.hash;if(switch_pc != "#pc"){if(/iphone|ipod|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='http://www.wuhannews.cn/m';}}})(window);</script>
<meta name="mobile-agent" content="format=html5;url=http://www.wuhannews.cn/m"/>
<link href="http://www.wuhannews.cn/m" rel="alternate" media="only screen and (max-width:1000px)"/>
第五种:(推荐)
<meta http-equiv="mobile-agent" content="format=xhtml;url=/m/index.asp">
<script type="text/javascript">if(window.location.toString().indexOf('pref=padindex') != -1){}else{if(/AppleWebKit.*Mobile/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))){if(window.location.href.indexOf("?mobile")<0){try{if(/Android|Windows Phone|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)){window.location.href="m/index.asp";}else if(/iPad/i.test(navigator.userAgent)){}else{}}catch(e){}}}}</script>
第六种:在head中加入JS
<script type="text/javascript" src="http://www.wuhannews.cn/m/js/mobile.js"></script>
第七种:(与第五种一致,不同的只是在于/m/后边有无index.asp文件,效果一样)
<meta http-equiv="mobile-agent" content="format=xhtml;url=/m/">
<script type="text/javascript">if(window.location.toString().indexOf('pref=padindex') != -1){}else{if(/AppleWebKit.*Mobile/i.test(navigator.userAgent) ||
(/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))){if
(window.location.href.indexOf("?mobile")<0){try{if(/Android|Windows Phone|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)){window.location.href="/m/";}
else if(/iPad/i.test(navigator.userAgent)){}else{}}catch(e){}}}}</script>
第八种:
<link rel="alternate" type="application/vnd.wap.xhtml+xml" media="handheld" href="http://www.wuhannews.cn/m"/>
<script src="http://www.wuhannews.cn/js-bak/uaredirect.js?v=5.0" type="text/javascript"></script>
<script type="text/javascript">KZ.redirect("http://www.wuhannews.cn/m");</script>
第九种:使用腾讯js来判断客户端是否为手机
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=gb2312" http-equiv="Content-Type">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>网站首页</title>
<script type="text/javascript">
if(window.location.toString().indexOf('pref=padindex') != -1){
<br>}else{
if(/AppleWebKit.*Mobile/i.test(navigator.userAgent) <br> || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))){
if(window.location.href.indexOf("?mobile")<0){
try{
if(/Android|Windows Phone|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)){
window.location.href="http://xw.qq.com/index.htm";
}else if(/iPad/i.test(navigator.userAgent)){
window.location.href="http://www.hubeibbs.net/pad/"
}else{
window.location.href="http://xw.qq.com/simple/s/index/"
}
}catch(e){}
}
}
}
</script> |