微信跳转到浏览器内下载文件
1.微信里面是不能下载app的,所以需要检测,如果在微信内,弹出蒙层,提示点击右上角打开浏览器进行下载。
2.代码如下:
html:
<a href="" id="JdownApp"><img src="img/load-btn.png"/></a>
这里就是我的点击下载的按钮
<div class="wxtip" id="JweixinTip">
<span class="wxtip-icon"></span>
</div>
这里是隐藏的蒙层
js代码:
function weixinTip(ele) {
var ua = navigator.userAgent;
var isWeixin = !!/MicroMessenger/i.test(ua);
if (isWeixin) {
ele.onclick = function(e) {
window.event ? window.event.returnValue = false : e.preventDefault();
document.getElementById('JweixinTip').style.display = 'block';
}
document.getElementById('JweixinTip').onclick = function() {
this.style.display = 'none';
}
}
}
var btn1 = document.getElementById('JdownApp');//下载一
weixinTip(btn1);
css代码:
.wxtip{background: rgba(0,0,0,0.8); text-align: center; position: fixed; left:0; top: 0; width: 100%; height: 100%; z-index: 998; display: none;}
.wxtip-icon{width: 100%; height: 100%; background: url(../img/weixxin-tip.png) no-repeat; display: block; position: absolute; left: 350px; top: 100px;}
.wxtip-txt{margin-top: 107px; color: #fff; font-size: 16px; line-height: 1.5;}
另外就还需要一张图片