手机打开WEB网站自动打开移动版
日期:2015-12-02 / 人气: / 来源:
问:
网站设计有PC版和移动版两种,就是wap网站。
可是手机上面搜索,打开的还是PC版的。
需要做什么处理,或者提交吗,能让在手机打开的就是wap的网站。
解决办法:
在WEB网站加入一段判断的JS即可。
<script src="/style/uaredirect.js" type="text/javascript"></script>
<script type="text/javascript">uaredirect("http://m.dede58.com");</script>
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|iPad)/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}}}}; 作者: 推荐内容 Recommended
相关内容 Related
我们的解决方案 Our Services"智慧中国"我公司开发的多种监测及控制系统可以为您的生产、生活提供更好的智能解决方案。How are the services that we could provide to you, our attitude toward service, our service process, service advantages and the office environment in our eyes 我们的产品 Our products我们为您精心打造的品质产品,去感受不一样的工控仪表,服务于世界500强的企业为您服务。You can go to review our classic cases that we have picked for you so as to experience different office environments. The enterprise that has serviced world Top 500 enterprises will serve you as well. |