需求簡(jiǎn)述
今天一后臺(tái)同事問我:為什么從App里面分享下載鏈接到微信好友時(shí),打開提示“已停止訪問該網(wǎng)頁”,可是我的鏈接明明是可以在瀏覽器打開的啊。
于是我在微信公眾號(hào)中試了一下,發(fā)現(xiàn)果然不可以下載。通過google 發(fā)現(xiàn),原來是微信屏蔽了內(nèi)置瀏覽器的下載功能。那么有沒有解決辦法呢? 肯定是有的。
技術(shù)手段現(xiàn)在是可以實(shí)現(xiàn)微信內(nèi)直接下載app的功能的。下面給大家分享一下功能代碼和實(shí)現(xiàn)效果。、
實(shí)現(xiàn)教程:http://sk.go51w.cn/nt0014.html
功能實(shí)現(xiàn)后ios系統(tǒng)可在微信內(nèi)直接下載app,安卓則自動(dòng)跳轉(zhuǎn)瀏覽器下載。
1. App Store應(yīng)用實(shí)現(xiàn)效果

2. 企業(yè)版app實(shí)現(xiàn)效果

3. 安卓用戶則自動(dòng)打開手機(jī)瀏覽器下載app。
代碼編程
HTML代碼
var ua?= navigator.userAgent;
var isWeixin =??!!/MicroMessenger/i.test(ua);
CSS代碼
1 #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;}
2 #weixin-tip p{text-align:center;margin-top:10%;padding:0 5%;position:relative;}
3 #weixin-tip .close{color:#fff;padding:5px;font:bold 20px/24px simsun;text-shadow:0 1px 0 #ddd;position:absolute;top:0;left:5%;}
JS封裝代碼
1 var is_weixin = (function(){return navigator.userAgent.toLowerCase().indexOf(‘micromessenger’) !== -1})();
2 window.onload = function() {
3 var winHeight = typeof window.innerHeight != ‘undefined’ ? window.innerHeight : document.documentElement.clientHeight; //兼容IOS,不需要的可以去掉
4 var btn = document.getElementById(‘J_weixin’);
5 var tip = document.getElementById(‘weixin-tip’);
6 var close = document.getElementById(‘close’);
7 if (is_weixin) {
8 btn.onclick = function(e) {
9 tip.style.height = winHeight + ‘px’; //兼容IOS彈窗整屏
10 tip.style.display = ‘block’;
11 return false;
12 }
13 close.onclick = function() {
14 tip.style.display = ‘none’;
15 }
16 }
17 }
完成功能后,我們就算是解決了微信攔截分享鏈接的阻礙了,我們就可以直接在微信內(nèi)分享下載鏈接和二維碼進(jìn)行宣傳引流了。如此也能夠極大的提高自己的APP在微信中的推廣轉(zhuǎn)化率,充分利用微信的用戶群體來宣傳引流。