联 系 人:李总
联系电话:13759574266
在线 QQ:89417157
邮箱:13759574266@qq.com
微信号:ynlongtou
地址:昆明市滇缅大道旁昆建路5号108智库空间A座4楼
手机访问PC端实现自动跳转手机端代码的实现方法有很多,云南龙头科技有限公司小编列出如下几种供大家参考:
第一种:使用百度出品的uaredirect.js来判断客户端是否为手机
<script src="http://www.ynlongtou.com/js-bak/uaredirect-baidu.js" type="text/javascript"></script><script type="text/javascript">uaredirect("http://www.ynlongtou.com/m");</script>
第二种:进入网站自动跳转
<meta http-equiv="refresh" content="0;url= /m ">
第三种:
<script type="text/javascript">
var commonURL = 'http://www.ynlongtou.com/';
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.ynlongtou.com/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.ynlongtou.com/m';}}})(window);</script>
<meta name="mobile-agent" content="format=html5;url=http://www.ynlongtou.com/m"/>
<link href="http://www.ynlongtou.com/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.ynlongtou.com/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.ynlongtou.com/m"/>
<script src="http://www.ynlongtou.com/js-bak/uaredirect.js?v=5.0" type="text/javascript"></script>
<script type="text/javascript">KZ.redirect("http://www.ynlongtou.com/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.qq.com/pad/"
}else{
window.location.href="http://xw.qq.com/simple/s/index/"
}
}catch(e){}
}
}
}
</script>
扫描关注官方微信