那么,如何识别手机端并自动跳转呢?
在之间增加如下代码。
pc首页跳转
<link rel=”alternate” media=”only screen and (max-width: 640px)” href=”http://m.xxxx.com/”> <script src=”/skin/js/uaredirect.js” type=”text/javascript”></script> <script type=”text/javascript”>uaredirect(“http://m.xxxx.com/”); </script>
pc列表页跳转
<link rel=”alternate” media=”only screen and (max-width: 640px)” href=”http://m.xxxx.com <?=sys_ReturnBqClassUrl($class_r[$GLOBALS[navclassid]]);?>”> <script src=”http://m.xxxx.com/js/uaredirect.js” type=”text/javascript”></script> <script type=”text/javascript”> uaredirect(“http://m.xxxx.com<?=sys_ReturnBqClassUrl($class_r[$GLOBALS[navclassid]]);?>”); </script>
pc内容页跳转
<link rel=”alternate” media=”only screen and (max-width: 640px)” href=”http://m.xxxx.com[!–titleurl–]”> <script src=”http://www.xxxx.com/js/uaredirect.js” type=”text/javascript”></script> <script type=”text/javascript”> uaredirect(“http://m.xxxx.com[!–titleurl–]”); </script>
pc端跳转手机端js代码
uaredirect.js 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){f=f+”/#m/”+a;b=true}else{if(isSubdomain(arguments[1],e)==2){f=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)){h=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{c=c.replace(“.”,”\\.”);var a=new RegExp(“\\.”+c+”$”);if(b.match(a)){return 2}else{return 0}}}};
声明:有的资源均来自网络转载,版权归原作者所有,如有侵犯到您的权益 请联系邮箱:www.ssswm.com@qq.com 我们将配合处理!
原文地址:《完美国际私服电脑端自动跳转到手机端方法》发布于2020-07-02 22:10:37