码迷,mamicode.com
首页 > 微信 > 详细

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

时间:2020-01-21 21:33:31      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:open   like   isa   segment   name   title   styles   ESS   打不开   


<!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实现网页只能在微信内打开,浏览器打不开!

标签:open   like   isa   segment   name   title   styles   ESS   打不开   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!