首页 > 微信 > 详细

js实现网页只能在微信内打开,浏览器打不开!

时间:2020-01-21 21:07:41      阅读:94      评论:0      收藏:0      [点我收藏+]

标签:doctype   navi   inner   spa   html   ()   


<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0">
    </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>‘;
            }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 = ‘打开成功!‘;
            }
        </script>
    </body>
</html>

技术分享图片

demo:点击查看DEMO

js实现网页只能在微信内打开,浏览器打不开!

标签:doctype   navi   inner   spa   html   ()   

原文:https://www.cnblogs.com/homehtml/p/12225753.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 bubuko.com 版权所有 鲁ICP备09046678号-4
打开技术之扣,分享程序人生!
             

鲁公网安备 37021202000002号