网页设置只能在手机微信客户端访问,禁止在电脑端访问包括微信电脑版

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了网页设置只能在手机微信客户端访问,禁止在电脑端访问包括微信电脑版相关的知识,希望对你有一定的参考价值。

 <script type="text/javascript">

     function checkFlag(){
         var userType=navigator.userAgent;
         var Agents=["android","iPhone","SymbianOS","Windows Phone","iPad","iPod"];
     var flag=false;
     for(var i=0;i<Agents.length;i++){
         if(userType.indexOf(Agents[i])>0){
             flag=true;
             break;
         }
     }
     return flag;
     }
    init();
    function init(){
    var  flag=checkFlag();
    if(flag){
        var ua = navigator.userAgent.toLowerCase();
                 var isWeixin = ua.indexOf(‘micromessenger‘) != -1;
                 var isAndroid = ua.indexOf(‘android‘) != -1;
                 var isios = (ua.indexOf(‘iphone‘) != -1) || (ua.indexOf(‘ipad‘) != -1);
    if (!isWeixin) {
                 document.head.innerhtml = ‘<title>抱歉,出错了</title><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0"><link rel="stylesheet" type="text/css" href="https://res.wx.qq.com/open/libs/weui/0.4.1/weui.css">‘;
                 document.body.innerHTML = ‘<div class="weui_msg"><div class="weui_icon_area"><i class="weui_icon_info weui_icon_msg"></i></div><div class="weui_text_area"><h4 class="weui_msg_title">请在微信客户端打开链接</h4></div></div>‘;
    }else{
          window.location.href ="xxxx.html";
    }
    }else{

        document.head.innerHTML = ‘<title>抱歉,出错了,请在手机微信打开</title><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0"><link rel="stylesheet" type="text/css" href="https://res.wx.qq.com/open/libs/weui/0.4.1/weui.css">‘;
         document.body.innerHTML = ‘<div class="weui_msg"><div class="weui_icon_area"><i class="weui_icon_info weui_icon_msg"></i></div><div class="weui_text_area"><h4 class="weui_msg_title">请在手机端微信客户端打开链接</h4></div></div>‘;

    }

    }

</script>

以上是关于网页设置只能在手机微信客户端访问,禁止在电脑端访问包括微信电脑版的主要内容,如果未能解决你的问题,请参考以下文章

手机怎样禁止访问某个网站?

网页设置那 可不可以设置禁止打开某个网页?

禁止访问

ThinkPHP中判断是手机端还是电脑端访问的方法

电脑Google浏览器该网页已被禁止怎么办?

网页无法访问如何解决