帝国CMS怎样识别跳转手机端(user-agent) 作者:30yi.cn     时间:2020-05-13

简单概括
帝国cms需要对首页跳转、列表页跳转以及内容页跳转进行分开设置,根据页面分类不同跳转的代码略有不同。

使用帝国CMS创建多端时难免会遇到这个问题:怎样根据PC客户端/手机客户端跳转到对应的页面。

 

根据帝国CMS规则,可插入一段script代码识别用户端,而后需要进行三类设置,分别是首页跳转、列表页跳转以及内容页跳转,根据页面分类不同跳转代码略有不同。

 

本文以主站30yi.cn跳转手机端m.30yi.cn为例,在页头<header>标签中插入如下代码(<script>js跳转/meta标签二种形式的跳转二选一即可)。示例如下:

 

帝国CMS首页跳转手机端:

<script type="text/javascript">

try {var urlhash = window.location.hash;if (!urlhash.match("fromapp"))

{if ((navigator.userAgent.match(/(iPhone|iPod|Android|ios|iPad)/i)))

{window.location="m.30yi.cn/";}}}

catch(err)

{

}</script>

<meta name="mobile-agent" content="format=xhtml;url=m.30yi.cn/">

 

 

帝国CMS列表页跳转手机端:

<script type="text/javascript">

try {var urlhash = window.location.hash;if (!urlhash.match("fromapp"))

{if ((navigator.userAgent.match(/(iPhone|iPod|Android|ios|iPad)/i)))

{window.location="m.30yi.cn<?=sys_ReturnBqClassUrl($class_r[$GLOBALS[navclassid]]);?>";}}}

catch(err)

{

}</script>

<meta name="mobile-agent" content="format=xhtml;url=m.30yi.cn<?=sys_ReturnBqClassUrl($class_r[$GLOBALS[navclassid]]);?>">

 

 

帝国CMS内容页跳转手机端:

<script type="text/javascript">

try {var urlhash = window.location.hash;if (!urlhash.match("fromapp"))

{if ((navigator.userAgent.match(/(iPhone|iPod|Android|ios|iPad)/i)))

{window.location="m.30yi.cn[!--titleurl--]";}}}

catch(err)

{

}</script>

<meta name="mobile-agent" content="format=xhtml;url=m.30yi.cn[!--titleurl--]">

 

注意:

1、由于是跳转关系,主站网站地址必须填“/”,附件地址加入主站http://30yi.cn/

2、如果手机端放在主端内,请对手机端目录进行301重定向避免分权/信息重复惩罚