1. 程式人生 > >從微信端跳到外部瀏覽器進行apk檔案下載

從微信端跳到外部瀏覽器進行apk檔案下載

需求:從微信公眾號裡的欄目跳到外部瀏覽器進行apk檔案下載

原因:在微信內不允許直接下載apk

這裡有一個解決方案,直接上關鍵程式碼

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta content="initial-scale=1.0, minimum-scale=1.0, maximum-scale=2.0, user-scalable=no, width=device-width" name="viewport">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name="description" content="" />
    <meta name="keywords" content="" />
    <!--<link rel="stylesheet" type="text/css" href="__CSS__/ionic.min.css"> -->
    <link rel="stylesheet" type="text/css" href="css/swiper.min.css">
    <link rel="stylesheet" type="text/css" href="css/wx.css">
    <title>下載APP</title>
</head>
<style>
    *{
        margin:0px;
        padding:0px;
    }
    body{
        background:#fff;
        /*overflow:hidden;*/
    }
    #weixin-tip img{
        width:100%;
    }
    #weixin-tip{display:none;position:fixed;left:0;top:0;background:rgba(0,0,0,0.8);filter:alpha(opacity=80);width:100%;height:100%;z-index:100;}
    #weixin-tip p{position:relative;width:90%;margin:0 auto;}
    #weixin-tip .close{color:#fff;padding:5px;font:bold 20px/24px simsun;text-shadow:0 1px 0 #ddd;position:absolute;top:0;left:0;}
</style>
<body>
    <a id="J_weixin" href='檔案下載地址'>
    <div id="weixin-tip"><p><img src="__STATIC__/index/lib/tp_1.png" alt="微信開啟"/><span id="close" title="關閉" class="close">×</span></p></div>
</body>
<script>
    var is_weixin = (function(){return navigator.userAgent.toLowerCase().indexOf('micromessenger') !== -1})();
    window.onload = function() {
        var winHeight = typeof window.innerHeight != 'undefined' ? window.innerHeight : document.documentElement.clientHeight; //相容IOS,不需要的可以去掉
        var btn = document.getElementById('J_weixin');
        var tip = document.getElementById('weixin-tip');
        var close = document.getElementById('close');
        if (is_weixin) {
            btn.onclick = function(e) {
                tip.style.height = winHeight + 'px'; //相容IOS彈窗整屏
                tip.style.display = 'block';
                return false;
            }
            close.onclick = function() {
                tip.style.display = 'none';
            }
        }
    }
    // var remap=document.getElementById('remap');
    //    remap.style.height=(winHeight-20) + 'px';     
</script>
</html>

親測沒有問題。

效果圖: