秋痕语录

H5页面 浏览器唤醒/打开微信

QQ截图20181128120005.jpg

此方法可以判断手机是否安装微信 并打开

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
        <title>判断手机是否安装微信</title>
    </head>
    <body>
        <a href="javascript:testApp('weixin://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=MzU1Njc2ODk5MQ==&scene=126#wechat_redirect')" class="dl-btn" id="download">打开微信</a> 
    <script>
    function testApp(url) { 
          var timeout, t = 1000, hasApp = true; 
          setTimeout(function () { 
            if (!hasApp) { 
                //没有安装微信
                var r=confirm("您没有安装微信,请先安装微信!");
                if (r==true){
                    location.href="http://weixin.qq.com/"
                }
            }else{
                //安装微信
            }
            document.body.removeChild(ifr); 
          }, 2000) 
          
          var t1 = Date.now(); 
          var ifr = document.createElement("iframe"); 
          ifr.setAttribute('src', url); 
          ifr.setAttribute('style', 'display:none'); 
          document.body.appendChild(ifr); 
          timeout = setTimeout(function () { 
             var t2 = Date.now(); 
             if (!t1 || t2 - t1 < t + 100) { 
               hasApp = false; 
             } 
          }, t); 
        } 
    </script>
    </body>
</html>


打赏

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

©2017 Lxy 豫ICP备17013024号
Copyright2017 lixueyang All Rights Reserved

公告

Welcome to my blog, where you will experience the thrill of not exceeding