• 限制网页仅可在微信客户端打开


    效果:判断网页是否是在微信浏览器打开;

    $(function(){
        //判断页面是否是在微信浏览器打开
        //对浏览器的UserAgent进行正则匹配,不含有微信独有标识的则为其他浏览器
        var useragent = navigator.userAgent;
        if (useragent.match(/MicroMessenger/i) != 'MicroMessenger') {
            window.location.href = "wxError.html";//若不是微信浏览器,跳转到温馨error页面
        }
    })

    微信提示页面(代码为微信原生代码);

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="utf-8">
            <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
        </head>
        <body>
            <script type="text/javascript">
                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>';
                }
            </script>
        </body>
    </html>
    function is_weixn(){  
        var ua = navigator.userAgent.toLowerCase();  
        if(ua.match(/MicroMessenger/i)=="micromessenger") {//这就是微信用的内置浏览器  
            return true;  
        } else {  
            return false;  
        }  
    }
    <script>
            var ua = navigator.userAgent.toLowerCase();
            var isWeixin = ua.indexOf('micromessenger') != -1;
            if (!isWeixin) {
                window.location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=888"
            }
    </script>
  • 相关阅读:
    poj 3125 Printer Queue(STL注意事项)
    poj 2823 Sliding Window (STL超时版)
    poj 1088 滑雪 详解
    poj 2983 Is the Information Reliable?
    poj 2524 Ubiquitous Religions (STL与非STL的对比)
    高精度算法集合
    zTree v2.6 v3.0 初始化 / 方法对比
    下面是关于rownum的介绍(oracle)
    web性能优化
    jQueryEasyui,DataGrid几个常用的操作
  • 原文地址:https://www.cnblogs.com/lazb/p/13657042.html
Copyright © 2020-2023  润新知