14yks - 2016/3/28 15:57:43
手机版已经建好,使用www.***.com/wap能访问,但如何在输入www.***.com时能根据设备自动切换?
我在手机上输入www.***.com还是访问的PC版,不能自动切换到手机版。
14yks - 2016/3/28 17:08:40
暂时用这个实现了:
- <script src="http://siteapp.baidu.com/static/webappservice/uaredirect.js" type="text/javascript"></script><script type="text/javascript">uaredirect("你的手机版网址");</script>
复制代码下面这个也可以:
thisUrl.substr(0,thisUrl.lastIndexOf('/')+1)+'wap/';这个就是网址,这个是相对的wap目录。
- <script type="text/javascript">
- // JavaScript Document
- function urlredirect() {
- var sUserAgent = navigator.userAgent.toLowerCase();
- if ((sUserAgent.match(/(ipod|iphone os|midp|ucweb|android|windows ce|windows mobile)/i))) {
- // PC跳转移动端
- var thisUrl = window.location.href;
- window.location.href = thisUrl.substr(0,thisUrl.lastIndexOf('/')+1)+'wap/';
-
- }
- }
- urlredirect();
- </script>
复制代码将其放入中文版的
首页中的head区,注意只能是放在首页的,我最初放在基本设置中,导致该代码一直执行而无法正常跳转。
Vipzz - 2016/3/28 17:16:22
谢谢分享。。。mark备用!