页面仅限微信端访问JS代码

    页面仅限微信端访问JS代码:

    <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>
    或
    <script>
    $(function(){
    	//判断页面是否是在微信浏览器打开
    	//对浏览器的UserAgent进行正则匹配,不含有微信独有标识的则为其他浏览器
        var useragent = navigator.userAgent;
        if (useragent.match(/MicroMessenger/i) != 'MicroMessenger') {
            window.location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=888";//若不是微信浏览器,跳转到温馨error页面
        }
    })
    </script>