zoukankan      html  css  js  c++  java
  • 微信为啥不能直接下载.apk安装包

    今天遇到一个很蛋疼问题,我们的微信公众号上想放一个下载自己公司app的点击按钮,如果是苹果手机点击这个按钮就直接跳转到苹果的appstore,如果是android手机的话,就直接跳我们的服务器下载apk链接,可是一个很蛋疼的问题出现了,微信  不支持   ,所以,我们就想了一个办法,点击这个按钮,然后让其在浏览器上打开,最后这个问题就ok完美解决了,下面分享一下代码和截图:

    源码下载github:https://github.com/TopGuo/weixinpop

    在线演示:yipin361.com/zyappd/index.html


    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
        <title>周翼单车app下载</title>
        <script src="js/bootstrap/js/Jquery.js"></script>
    </head>
    
    <body>
        <div align="center">
            <img src="img/bg.png" style="margin: 0 auto ">
    
            <a id="imgId"><img src="img/btn.png"></a>
    
    
        </div>
    
    
        <script language="javascript">
            $(function () {
    
                $("#imgId").click(function () {
                    download();
                });
            });
    
            function download() {
                var cssText =
                    "#weixin-tip{position: fixed; left:0; top:0; background: rgba(0,0,0,0.8); filter:alpha(opacity=80);  100%; height:100%; z-index: 100;} #weixin-tip p{text-align: center; margin-top: 10%; padding:0 5%;}";
                var u = navigator.userAgent;
                if (u.indexOf('Android') > -1 || u.indexOf('Linux') > -1) { //安卓手机
                    //判断使用环境
                    if (is_weixin()) {
                        loadHtml();
                        loadStyleText(cssText);
                    } else {
                        window.location.href = "http://android.zhouyibike.com/app-release.apk";
                    }
                } else if (u.indexOf('iPhone') > -1) { //苹果手机
                    window.location.href = "https://itunes.apple.com/cn/app/id1239249767?mt=8";
                } else if (u.indexOf('Windows Phone') > -1) {
                    //winphone手机
                    alert("机型不匹配!");
                }
            }
    
            function is_weixin() {
                var ua = navigator.userAgent.toLowerCase();
                if (ua.match(/MicroMessenger/i) == "micromessenger") {
                    return true;
                } else {
                    return false;
                }
            }
    
            function loadHtml() {
                var div = document.createElement('div');
                div.id = 'weixin-tip';
                div.innerHTML = '<p><img src="live_weixin.png" alt="请在微浏览器打开"/></p>';
                document.body.appendChild(div);
            }
    
            function loadStyleText(cssText) {
                var style = document.createElement('style');
                style.rel = 'stylesheet';
                style.type = 'text/css';
                try {
                    style.appendChild(document.createTextNode(cssText));
                } catch (e) {
                    style.styleSheet.cssText = cssText; //ie9以下
                }
                var head = document.getElementsByTagName("head")[0]; //head标签之间加上style样式
                head.appendChild(style);
            }
        </script>
    
    </body>
    
    </html>

    效果图如下:

  • 相关阅读:
    随手记几个容易被忽略的bug
    fiddler常见应用场景
    浅谈软件测试流程
    http抓包实战之http协议初始、fiddler初识
    http之header详解
    http协议基础(一)
    Fiddler抓包工具总结二(转自小坦克)
    接口测试总结
    [Python][爬虫]利用OCR技术识别图形验证码
    [总结]JS在Selenium中的使用
  • 原文地址:https://www.cnblogs.com/gdsblog/p/7799112.html
Copyright © 2011-2022 走看看