现在手机用户越来越多,在生活中甚至手机比电脑用的还多,当前开发的网站大都是PC和WAP版并存,但是很少有用户愿意去记住一个网站的两个端的不同域名,所以需要我们做一些设置,在用户访问首页的时候,进行分析跳转,现将网上流行的几种方式汇总如下,希望对大家有用:
【跳转代码一】
XML/HTML代码
<script type="text/javascript">
var urlhash = window.location.hash;
{
{
}
}
{
</script>
【跳转代码二】(利用百度Site App代码判断手机访问)
XML/HTML代码
<script language="JavaScript">function uaredirect(f){try{if(document.getElementById("bdmark")!=null){return}var b=false;if(arguments[1]){var e=window.location.host;var a=window.location.href;if(isSubdomain(arguments[1],e)==1){ff=f+"/#m/"+a;b=true}else{if(isSubdomain(arguments[1],e)==2){ff=f+"/#m/"+a;b=true}else{f=a;b=false}}}else{b=true}if(b){var c=window.location.hash;if(!c.match("fromapp")){if((navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i))){location.replace(f)}}}}catch(d){}}function isSubdomain(c,d){this.getdomain=function(f){var e=f.indexOf("://");if(e>0){var h=f.substr(e+3)}else{var h=f}var g=/^www\./;if(g.test(h)){hh=h.substr(4)}return h};if(c==d){return 1}else{var c=this.getdomain(c);var b=this.getdomain(d);if(c==b){return 1}else{cc=c.replace(".","\\.");var a=new RegExp("\\."+c+"$");if(b.match(a)){return 2}else{return 0}}}};uaredirect("m.your-website.com");</script>
【跳转代码三】
XML/HTML代码
<script language="JavaScript">
{
var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");
{
{
}
}
if(navigator.platform.indexOf('iPad') != -1)
window.location=url;
//做这一部分是因为Android手机的内核也是Linux
var check = navigator.appVersion;
{
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)
}
}
mobile_device_detect("http://m.your-website.com");