微信掃碼下載APK遮罩提示示例
由於微信的限制,應用檔案在內建瀏覽器中下載全部被遮蔽掉,造成很多人用微信掃描二維碼下載時,介面顯示一片空白,容易誤導以為在下載呢。按照當前主流習慣,做一個提示使用者在瀏覽器中開啟下載的遮罩。網上很多現成的例子,解釋的也很詳細,但感覺沒有直接上手可用的例子,因此,我打算寫個示例。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>下載示例</title>
<style type="text/css">
#weixin-tip {
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 {
text-align: center;
margin-top: 10%;
padding: 0 5%;
}
</style>
</head>
<body>
<div id="weixin_tip" style="width: 100%; height: 100%;">
<p>
<img src="live_weixin.png" alt="微信開啟" style="width: 100%; height: 100%;" />
</p>
</div>
</body>
<script type="text/javascript">
function is_weixin() {
var ua = navigator.userAgent.toLowerCase();
if (ua.match(/MicroMessenger/i) == "micromessenger") {
return true;
} else {
return false;
}
}
// 微信內建瀏覽器開啟,只是顯示遮罩層,其他瀏覽器進行連線跳轉
if (is_weixin()) {
document.getElementById("weixin_tip").style.display="block";
} else {
document.getElementById("weixin_tip").style.display="none";
window.location.href = "這裡修改為自己的下載地址";
}
</script>
</html>
記得替換一下下載地址和圖片路徑就直接可以用了。
圖片可以從 https://github.com/kujian/weixinTip?utm_source=caibaojian.com 這裡下載
注意:我是參考了 http://caibaojian.com/weixin-tip.html 的來做的,圖片也是來源這裡