帝国CMS判断PC端跳转手机端方法,亲测可用。
首先新建一个JS文件,复制以下代码
function browserRedirect(url) { var sUserAgent = navigator.userAgent.toLowerCase(); 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){ window.location.replace(url); } }
然后再将下面代码复制到对应模板
首页跳转
<script src='https://www.11px.cn/wap.js' language='javascript'></script> <script type="text/javascript"> browserRedirect("https://www.11px.cn/"); </script>
封面页跳转
<script src='https://www.11px.cn/wap.js' language='javascript'></script> <script type="text/javascript"> browserRedirect("https://www.11px.cn/e/public/ClassUrl/?classid=[!--self.classid--]"); </script>
列表页跳转
<script src='https://www.11px.cn/wap.js' language='javascript'></script> <script type="text/javascript"> browserRedirect("https://www.11px.cn/e/public/ClassUrl/?classid=[!--self.classid--]"); </script>
内容页跳转
<script src='https://www.11px.cn/wap.js' language='javascript'></script> <script type="text/javascript"> browserRedirect("https://www.11px.cn/[!--titleurl--]"); </script>
记得将以上代码中域名、路径替换成你的域名、文件路径。
本文转载自:精准像素:11px.cn ,感谢作者分享实用知识