杰奇2.4全站设备识别跳转js,具体实现方案

本文阅读 3 分钟
广告

相对于二次开发那些,这个确实是算简单的了,只需要根据网上的js自己补充而已,但是相对于每个模板都配置一条跳转规则,我还是有个简单的办法,不过还是得配合已经设置好的伪静态。在这篇教程里,我就简单说明一下电脑和手机端两边的配置,算是简单的记录,如果对伪静态有疑惑的,可以参考之前的文章杰奇2.4全站伪静态参考写法,附多环境配置
比较重要的页面主要是首页,书库,分类,小说信息,充值,目录,小说阅读,但是一般来说目录和小说阅读的头部是放置在单个文件中,不和其它页面共用。

2019/09/30补充,感谢群友在评论区的留言,直接解决了我过于复杂的思路,他的内容如下:

只需修改公共js一个文件即可: /scripts/common.js
添加几行代码:
if( is_mobile ){ //如果设备是移动端
  if(window.location.host !== "wap.xx.com"){ //如果当前域名不是m站域名
  window.location='http://wap.xx.com/'+window.location.pathname; //带路径跳到m站
  }
}

这样可以非常快捷的解决所有问题,而无需太多代码,所以我之前写的内容,就当做一个模板标签的玩法用来参考吧。

假如:

电脑端网址为:pc.xx.com
手机端网址为:wap.xx.com

教程开始

首先是PC端的修改

1.在PC端的/themes/目录中找到当前设置的模板,进入后找到theme.html,在它的head标签对中加入如下代码:

<script type="text/javascript">      
function browserRedirect() {
  var sUserAgent = navigator.userAgent.toLowerCase();
  var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
  var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
  var bIsMidp = sUserAgent.match(/midp/i) == "midp";
  var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
  var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
  var bIsAndroid = sUserAgent.match(/android/i) == "android";
  var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
  var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
  if(bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM){
  {?if $jieqi_thisfile|basename == 'articlefilter.php'?}
  window.location.href = "http://wap.xx.com/modules/article/articlefilter.php";
  {?else if $jieqi_thisfile|basename == 'articlelist.php'?}
  window.location.href = "http://wap.xx.com/sort/{?$sortid?}/1.html";
  {?else if $jieqi_thisfile|basename == 'buyegold.php'?}
  window.location.href = "http://wap.xx.com/modules/pay/buyegold.php";
  {?else if $jieqi_thisfile|basename == 'articleinfo.php'?}
  window.location.href = "http://wap.xx.com/book/{?$articleid?}";
  {?else?}
  window.location.href = "http://wap.xx.com/";
  {?/if?}
  }
}
browserRedirect();
</script>

2.目录页和章节页头部可能在themer.html,也可能是/modules/article/templates/里面的style.html和index.html,同样是在head标签对加入如下代码。

<script type="text/javascript">      
function browserRedirect() {
  var sUserAgent = navigator.userAgent.toLowerCase();
  var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
  var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
  var bIsMidp = sUserAgent.match(/midp/i) == "midp";
  var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
  var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
  var bIsAndroid = sUserAgent.match(/android/i) == "android";
  var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
  var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
  if(bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM){
  {?if $jieqi_thisfile|basename == 'reader.php'?}
  window.location.href = "http://wap.xx.com/index/{?$articleid?}/1/asc";
  {?else if $chapterid != ''?}
  window.location.href = "http://wap.xx.com/book/{?$articleid?}/{?$chapterid?}.html";
  {?else?}
  window.location.href = "http://wap.xx.com/";
  {?/if?}
  }
}
browserRedirect();
</script>

然后是WAP端的修改:

1.在WAP端的/themes/目录中找到当前设置的模板,进入后找到theme.html,在它的head标签对中加入如下代码:

<script>
  if( navigator.userAgent.match(/Android/i)
     || navigator.userAgent.match(/webOS/i)
     || navigator.userAgent.match(/iPhone/i)
     || navigator.userAgent.match(/iPad/i)
     || navigator.userAgent.match(/iPod/i)
     || navigator.userAgent.match(/BlackBerry/i)
     || navigator.userAgent.match(/Windows Phone/i)
    ){
  }else{
  {?if $jieqi_thisfile|basename == 'articlefilter.php'?}
  window.location.href = "http://pc.xx.com/modules/article/articlefilter.php";
  {?else if $jieqi_thisfile|basename == 'articlelist.php'?}
  window.location.href = "http://pc.xx.com/sort/{?$sortid?}/1.html";
  {?else if $jieqi_thisfile|basename == 'buyegold.php'?}
  window.location.href = "http://pc.xx.com/modules/pay/buyegold.php";
  {?else if $jieqi_thisfile|basename == 'articleinfo.php'?}
  window.location.href = "http://pc.xx.com/book/{?$articleid?}";
  {?else?}
  window.location.href = "http://pc.xx.com/";
  {?/if?}
  }
</script>

2.目录页和章节页和pc差不多相同,一样的逻辑,就是目录页面的细节不一样。

<script>
  if( navigator.userAgent.match(/Android/i)
     || navigator.userAgent.match(/webOS/i)
     || navigator.userAgent.match(/iPhone/i)
     || navigator.userAgent.match(/iPad/i)
     || navigator.userAgent.match(/iPod/i)
     || navigator.userAgent.match(/BlackBerry/i)
     || navigator.userAgent.match(/Windows Phone/i)
    ){
  }else{
  {?if $jieqi_thisfile|basename == 'reader.php'?}
  window.location.href = "http://pc.xx.com/index/{?$articleid?}";
  {?else if $chapterid != ''?}
  window.location.href = "http://pc.xx.com/book/{?$articleid?}/{?$chapterid?}.html";
  {?else?}
  window.location.href = "http://pc.xx.com/";
  {?/if?}
  }
</script>

就是以上这些了,如果有问题可以评论留言,我会解答的。

timg (3).jpg
规则之树版权所有,转载请注明来源,标明作者及原文链接

本文来自投稿,不代表本站立场,如若转载,请注明出处:https://www.ruletree.club/archives/1291/
[授权转载 ]《木卫二往事》
« 上一篇 06-10
怎样让机器有人类思维
下一篇 » 06-13
广告

发表评论

V注册会员 L评论等级
R2 条回复
  1. 逆水行舟Lv.1 说道:
    2019-09-30     Win 7 /    Chrome

    只需修改公共js一个文件即可: /scripts/common.js
    添加几行代码:
    if( is_mobile ){ //如果设备是移动端
    if(window.location.host !== "wap.xx.com"){ //如果当前域名不是m站域名
    window.location='http://wap.xx.com/'+window.location.pathname; //带路径跳到m站
    }
    }

没有更多评论了

作者信息

热门文章

标签TAG

热评文章