建站技巧 2025年06月7日
0 收藏 0 点赞 842 浏览 3579 个字
摘要 :

最近给客户部署了一套织梦的网站源码,由于要求手机端和PC端同步,所以就对移动端进行了适配。但是由于织梦移动端的模板代码是生成在m文件夹下,而对移动端又绑定了相应……

最近给客户部署了一套织梦网站源码,由于要求手机端和PC端同步,所以就对移动端进行了适配。但是由于织梦移动端的模板代码是生成在m文件夹下,而对移动端又绑定了相应的二级域名。所以造成了,网站在收录的时候,收录了m文件下的html页面,但是当在电脑端查看收录页面时,会发现有很多m路径下的收录页面,当访问的时候,打开的是移动网站的页面,这样对用户体验不好,所以需要做相应的跳转,以下的解决方法是建立在PC端是静态页面、而移动端是动态调用的基础之上,如果移动端页是静态页面,请自行查找解决办法。

移动端首页跳转至PC端首页的代码:

<script type="text/javascript">

   /*判断手机端访问*/
   var isMobile = {
     Android:function(){
       return navigator.userAgent.match(/Android/i) 
       ? true:false;
     },

     BlackBerry:function(){
       return navigator.userAgent.match(/BlackBerry/i) 
       ? true:false;
     },

     iOS:function(){
       return navigator.userAgent.match(/iPhone|iPad|iPod/i) 
       ? true:false;
     },

     Windows:function(){
       return navigator.userAgent.match(/IEMobile/i) 
       ? true:false;
     },

     any:function(){
       return (isMobile.Android()||isMobile.BlackBerry() 
       ||isMobile.iOS()||isMobile.Windows());
     }

   };

     if(!isMobile.any()) {
       window.location.href = "PC端网址";
    }
 </script>

移动端文章页面跳转至PC端代码:

<script type="text/javascript">

   /*判断手机端访问*/
   var isMobile = {
   Android:function(){
      return navigator.userAgent.match(/Android/i) 
      ? true:false;
   },

    BlackBerry:function(){
      return navigator.userAgent.match(/BlackBerry/i) 
      ? true:false;
   },

   iOS:function(){
      return navigator.userAgent.match(/iPhone|iPad|iPod/i)
      ? true:false;
   },

   Windows:function(){
      return navigator.userAgent.match(/IEMobile/i)
      ? true:false;
   },

   any:function(){
      return (isMobile.Android()||isMobile.BlackBerry() 
      || isMobile.iOS()||isMobile.Windows());
   }

  };

    if(!isMobile.any()) {
      window.location.href = "{dede:field.id runphp='yes'}
      $id=@me;@me='';$url=GetOneArchive($id);
      @me=$url['arcurl'];{/dede:field.id}";
 }
 </script>

织梦网站在电脑端访问手机端页面自动跳转至对应的PC端

移动端列表页面跳转至PC端代码:

把以下代码加到 /include/helpers/extend.helper.php 文件最后。

if ( ! function_exists('itemCurUrl'))
{
    /**
     * 获取当前列表页或内容页的URL
     * 未经大量测试,一定会有不如意的地方,使用时注意测试观察
     *
     * 列表页使用方法:
     * dede:field.id runphp='yes'}@me=itemCurUrl(@me,'list');
     {/dede:field.id}
     * 内容页使用方法:
     * 
     dede:field.id runphp='yes'}@me=itemCurUrl(@me,'view');
     {/dede:field.id}
     *
     * @param int $id 列表ID或文章ID
     * @param string $type 分类,list:列表页,view:内容页
     * @return string
     */
function itemCurUrl($id, $type='list') {
  global $dsql;
  if($type == 'list'){
    $sql="SELECT * FROM `dede_arctype` WHERE `id`='$id' ";
    $info=$dsql->GetOne($sql);
    $url=GetOneTypeUrlA($info);
      return $url;
    }else{
      $arr = GetOneArchive($id);
      if(!empty($arr['ismake'])){ // 静态页面
        return $arr['arcurl'];
      }else{ // 动态页面
        return '/plus/view.php?aid='.$arr['aid'];
     }
   }
  }
}

然后在列表页的head部分加入以下代码:

<script type="text/javascript">

   /*判断手机端访问*/
   var isMobile = {
   Android: function () {
     return navigator.userAgent.match(/Android/i) 
     ? true:false;
   },

   BlackBerry:function(){
     return navigator.userAgent.match(/BlackBerry/i) 
     ? true:false;
   },

   iOS:function(){
     return navigator.userAgent.match(/iPhone|iPad|iPod/i) 
     ? true:false;
   },

   Windows:function(){
     return navigator.userAgent.match(/IEMobile/i) 
     ? true:false;
   },

   any:function(){
     return (isMobile.Android()||isMobile.BlackBerry() 
     || isMobile.iOS()||isMobile.Windows());
   }

 };

    if (!isMobile.any()) {
     window.location.href = "{dede:field.id runphp='yes'}
     @me=itemCurUrl(@me,'list');{/dede:field.id}"
   }
 </script>

以上代码由本站亲自测试,可正常运行。

微信扫一扫

支付宝扫一扫

版权: 转载请注明出处:https://www.zuozi.net/2574.html

管理员

相关推荐
2025-06-07

SSL证书已经越来越多的使用在网站,小程序和APP上,对于保障网络安全,加密数据信息有至关重要的作…

144
2025-06-07

‌PHP-FPM(PHP FastCGI Process Manager)是一个用于管理PHP进程的进程管理器,主要用于处理Web服务…

959
2025-06-07

友链(友情链接)和外链都是网站优化中的重要组成部分,它们都能在一定程度上提升网站的搜索引擎排…

305
2025-06-07

近日,源码码网注意到,站长之家旗下的SEO查询工具已取消域名的ICP备案主体显示,在此之前,我们需…

565
2025-06-07

为什么要隐藏服务器的真实ip? 当域名解析到服务器后,在不采取任何保护的措施下,通过域名能直接查…

1,018
2025-06-07

做SEO优化的同学,最常用的站长工具莫属百度站长平台,今天有同学问我,用百度站长工具查询网站关键…

1,024
发表评论
暂无评论

还没有评论呢,快来抢沙发~

助力内容变现

将您的收入提升到一个新的水平

点击联系客服

在线时间:08:00-23:00

客服QQ

122325244

客服电话

400-888-8888

客服邮箱

122325244@qq.com

扫描二维码

关注微信客服号