产品使用及交流论坛

注册

 

QQ登录

只需一步,快速开始

发新话题 回复该主题

手机版已经建好,能访问,但如何自动切换? [复制链接]

1#
手机版已经建好,使用www.***.com/wap能访问,但如何在输入www.***.com时能根据设备自动切换?
我在手机上输入www.***.com还是访问的PC版,不能自动切换到手机版。
分享 转发
TOP
2#

暂时用这个实现了:
  1. <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目录。
  1. <script type="text/javascript">
  2. // JavaScript Document
  3. function urlredirect() {
  4.     var sUserAgent = navigator.userAgent.toLowerCase();
  5.     if ((sUserAgent.match(/(ipod|iphone os|midp|ucweb|android|windows ce|windows mobile)/i))) {
  6.         // PC跳转移动端
  7.         var thisUrl = window.location.href;
  8.         window.location.href = thisUrl.substr(0,thisUrl.lastIndexOf('/')+1)+'wap/';
  9.         
  10.     }
  11. }
  12. urlredirect();
  13. </script>
复制代码
将其放入中文版的首页中的head区,注意只能是放在首页的,我最初放在基本设置中,导致该代码一直执行而无法正常跳转。
TOP
3#

谢谢分享。。。mark备用!
TOP
发新话题 回复该主题