解决方法:弹出一个遮罩提示用户在新的浏览器窗口打开。
再也不用管微信如何的更新,直接判断微信的ua,然后弹出一个遮罩提示用户在浏览器中打开下载。并且不加关闭的按钮。类似于下面这样子:
这样子用户就只能在浏览器中打开
另加一个判断手机QQ的UA
function is_mobileQQ() { var ua = navigator.userAgent.toLowerCase(); if (ua.match(/\sQQ/i) == " qq" && /iphone/i.test(ua) == false) { return true; } else { return false; } }
号外:由于这个代码一进入就是弹出提示,可能会影响用户其它操作,故而写了另一篇优化的代码,支持用户点击下载链接之后才弹出提示,并且还可以点击关闭。
HTML代码:
<a id="J_weixin" class="android-btn" href="#"><img src="img/android-btn.png" alt="微信扫描打开APP下载链接提示代码优化" alt="安卓版下载" /></a> <div id="weixin-tip"><p><img src="img/live_weixin.png" alt="微信扫描打开APP下载链接提示代码优化" alt="微信打开"/><span id="close" title="关闭" class="close">×</span></p></div>
CSS代码:
#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{text-align:center;margin-top:10%;padding:0 5%;position:relative;} #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封装代码:
// var is_weixin = (function() { //判断微信UA
// var ua = navigator.userAgent.toLowerCase();
// if (ua.match(/MicroMessenger/i) == "micromessenger") {
// return true;
// } else {
// return false;
// }
// })();
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';
}
}
}
文章来自与徐州网站建设公司,徐州网络公司哪家好,徐州网站无障碍建设,徐州集团网站建设公司
TAG: