纯代码实现wordpress手机端自动跳转指定页面

wordpress虽然自带了手机端响应功能,但是你的网站功能比较多的时候,靠纯电脑端转手机端是非常麻烦的事情,甚至很多功能没办法实现,这时独立做一个手机端页面就显得非常有必要,下面代码放在主题的header.php文件中即可实现手机端打开主页后自动跳转至你指定的页面,把代码中的链接修改为你想跳转页面即可。

<script type="text/javascript">
var mobileAgent = new Array("iphone", "ipod", "ipad", "android", "mobile", "blackberry", "webos", "incognito", "webmate", "bada", "nokia", "lg", "ucweb", "skyfire");
var browser = navigator.userAgent.toLowerCase();
var isMobile = false;
for (var i=0; i<mobileAgent.length; i++){
    if (browser.indexOf(mobileAgent[i])!=-1){
        isMobile = true;
        //alert(mobileAgent[i]);
        location.href = 'https://www.oppblog.com/mobile';
        break;
    }
}
</script>
评分 post
奥博说 版权所有丨如未注明 均为原创
转载请注明:https://www.oppblog.com/archives/497

发表评论