手机访问pc网站自动跳转手机端网站代码
这篇文章主要介绍了分享两个手机访问pc网站自动跳转手机端网站代码,需要的朋友可以参考下
4g降临,移动网站已经一发不可收拾,pc端和移动端官网并存。如何让别人访问你的pc端的官网直接跳转到移动端的网站呢?各位看官,小二上代码!来了!
第一种方法: 需要手机端也网页的数据同步
复制代码 代码如下:
<script type="text/javascript">
(function(){var ua=navigator.useragent.tolowercase();var bisipad=ua.match(/ipad/i)=="ipad";var bisiphoneos=ua.match(/iphone os/i)=="iphone os";var bisandroid=ua.match(/android/i)=="android";var biswm=ua.match(/windows mobile/i)=="windows mobile";if(bisipad||bisiphoneos||bisandroid||biswm){window.location.href="http://m.jb51.net/android/game/826.html"}})();
</script>
第二种方法:
<script language="javascript">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; } //做这一部分是因为android手机的内核也是linux //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appversion信息做判断 var check = navigator.appversion; if( check.match(/linux/i) ) { //x11是uc浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件 if(check.match(/mobile/i) || check.match(/x11/i)) { window.location=url; } } //类in_array函数 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://***.***.com");</script>
备注这里的
mobile_device_detect("http://***.***.com");//里面的地址填的就是您的移动端的网站地址呦。
![]() |
豫公网安备 41010202002486号 | ICP备案:豫ICP备18044432号-1 |