温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

微信提示浏览器打开代码——遮罩层提示代码实现!

发布时间:2020-06-04 16:11:18 来源:网络 阅读:1052 作者:退如有 栏目:软件技术

微信中打开链接时,弹出遮罩提示用户,请点击右上角在浏览器中打开如何实现?经搜集整理并且验证可用后总结出可用版本,给有需要的猿友


微信提示浏览器打开代码——遮罩层提示代码实现!

微信提示浏览器打开代码——遮罩层提示代码实现!


以下是代码部分:

第一步:判断微信的UA。

var ua = navigator.userAgent;

var isWeixin =  !!/MicroMessenger/i.test(ua);

第二步:引入默认隐藏层。

<a href="http://baidu.com/test.apk" id="JdownApp">点击下载APP</a>

<a href="http://baidu.com/test.apk" id="JdownApp2" class="btn-warn">点击下载APP2</a>

<div class="wxtip" id="JweixinTip">

<span class="wxtip-icon"></span>

<p class="wxtip-txt">点击右上角<br/>选择在浏览器中打开</p>

</div>

第三步:添加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: 52px; height: 67px; background: url(weixin-tip.png) no-repeat; display: block; position: absolute; right: 20px; top: 20px;}

.wxtip-txt{margin-top: 107px; color: #fff; font-size: 16px; line-height: 1.5;}

第四步:点击按钮显示隐藏层,点击隐藏层关闭,总的JS代码如下:

function weixinTip(ele){

var ua = navigator.userAgent;

var isWeixin = !!/MicroMessenger/i.test(ua);

if(isWeixin){

ele.οnclick=function(e){

window.event? window.event.returnValue = false : e.preventDefault();

document.getElementById('JweixinTip').style.display='block';

}

document.getElementById('JweixinTip').οnclick=function(){

this.style.display='none';

}

}

}

var btn1 = document.getElementById('JdownApp');//下载一

weixinTip(btn1);

var btn2 = document.getElementById('JdownApp2'); //下载二

weixinTip(btn2);

以上代码,你再也不用担心有多个按钮了。

全部代码演示:http://www.pushtool.cn/zhezhao/demo3

号外:这是微信中点击按钮才会提示在浏览器中打开遮罩的版本,还有:打开页面直接显示提示、安卓和苹果显示不同提示等其他版本。



向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI