建站帮助

诚信合作, 高质专业!

Phpcms V9自定义手机WAP模板新方法

2015-09-24 08:52:00 浏览 我要评论

这里我们就完成了手机版的设置了,然后我们在制作一套手机端模板放在mobile目录就好了。

如果我们要在PC端的内容里面加上当前页面手机端的链接,链接地址写法如下:

http://{str_replace('www.','m.',$_SERVER['SERVER_NAME'])}{$_SERVER['REQUEST_URI']}

反之,手机端加上PC端的链接:

http://{str_replace('m.','www.',$_SERVER['SERVER_NAME'])}{$_SERVER['REQUEST_URI']}

如果你使用的是静态页面,那么只要在模板页头加上以下JS代码就可以实现判断手机端自动跳转到手机端了。

具体代码:

<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 (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) {
 {if $catid=='' and $id==''}
 window.location.href="{APP_PATH}/index.php";
 {elseif $id=='' and $catid!=''}
 window.location.href="{APP_PATH}/index.php?m=content&c=index&a=lists&catid={$catid}";
 {else}
 window.location.href="{APP_PATH}/index.php?m=content&c=index&a=show&catid={$catid}&id={$id}";
 {/if}
 }
 }
 browserRedirect();
 
function closewindow() {
 $("#register-box").hide();
 }
 function openwindow() {
 $("#register-box").show();
 }
 </script>
 

以上内容,改编自axguowen,在此多谢!

 

最后,欢迎大家收听CMSYOU官方微博,在QQ群346494585探讨Phpcms!看完CMSYOU思优团队的文章有疑问,那就在下面评论留言吧!

我要收藏
点个赞吧

相关阅读

本月热门

精选推荐

在线客服

扫一扫,关注我们

扫一扫,关注我们