帝国CMS移动站自动适配跳转,首页/栏目频道/内容页各不同

2020-09-29 1,501 0

帝国CMS移动站(端)模板代码制作完成后,还需要在PC端代码中,加入识别移动端的代码,才能实现某种自动化——即代码判断是否是移动端,如果是,则跳转到对应的移动端页面。

其中要注意的关键点是:看似相同,然PC端首页模板、封面/栏目模板、内容页模板,要加入的跳转代码,是不一样的。

我们不一样的

具体功能实现代码如下:

1、PC端首页模板添加跳转代码

<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=”http://m.xxx.cn/”;}}}
catch(err)
{
}</script>
<meta name=”mobile-agent” content=”format=xhtml;url=http://m.xxx.cn/”>

(其中,http://m.xxx.cn,需要换成你的移动站网址,请提前做好解析及其他,如.htaccess中的移动端域名配置等......总之,移动网址能正常解析至你的移动站目录,打开能访问,是基础。)

2、PC端列表页或封面页模板添加跳转代码

<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=”http://m.xxx.cn<?=sys_ReturnBqClassUrl($class_r[$GLOBALS[navclassid]]);?>”;}}}
catch(err)
{
}</script>
<meta name=”mobile-agent” content=”format=xhtml;url=http://m.xxx.cn<?=sys_ReturnBqClassUrl($class_r[$GLOBALS[navclassid]]);?>”>

3、PC端内容页模板添加跳转代码

<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=”http://m.xxx.com[!–titleurl–]”;}}}
catch(err)
{
}</script>
<meta name=”mobile-agent” content=”format=xhtml;url=http://m.xxx.com[!–titleurl–]”>

最后就是测试,主要就是检查和比对移动端网址(手机可看,电脑看会方便些),尽量用手机浏览,看是否能正常访问浏览。如果不能,试着网址中加入移动端的目录名。

相关文章

wordpress6.5升级至6.8有风险!不得不采取曲线救国方式来解决
国际择校信息平台开发手记:5+2=23,均瑶集团下属的“世外教育系国际学校”,在上海究竟有多少所?
迅睿CMS后台内容加载不出来,解决方式是升级至最新框架及建站系统,附离线包升级实操记录
择校信息平台开发手记:2025中国国际化学校排名100强,有两家比均瑶集团旗下上海世外学校更强?
超好用!营销人木木老贼推荐“智谱清言 ”8个人工智能体AI工具
wordpress技术贴:缓存插件导致网站乱码、关键词自动加外链并标识

发布评论