修复了微信环境判断不正确的问题

This commit is contained in:
johlanse 2022-04-19 12:31:45 +08:00
parent 56f40d4338
commit 65ed8c6267
1 changed files with 12 additions and 10 deletions

View File

@ -4,18 +4,27 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Title</title> <title>Title</title>
<script src="qrcode.js"></script> <script src="qrcode.js"></script>
<style>
.wx{
font-size: 30px;
color: red;
}
</style>
</head> </head>
<body> <body>
<div> <div>
<button><a id="login" href="#"><h1>点击登录跳转学习强国app</h1></a></button> <button><a id="login" href="#"><h1>点击登录跳转学习强国app</h1></a></button>
</div> </div>
<div id="wx"></div> <div id="wx" class="wx"></div>
<div id="qrcode" style="margin-top: 10px"> <div id="qrcode" style="margin-top: 10px">
<img id="img" src="#" alt="#"/> <img id="img" src="#" alt="#"/>
</div> </div>
</body> </body>
<script> <script>
function load() { function load() {
if (isWechat()){
document.getElementById("wx").innerText = "当前为微信环境,请点击右上角浏览器中打开"
}
let search = window.location.search let search = window.location.search
search = search.substring(1,search.length) search = search.substring(1,search.length)
document.getElementById("login").setAttribute("href","dtxuexi://appclient/page/study_feeds?url="+search) document.getElementById("login").setAttribute("href","dtxuexi://appclient/page/study_feeds?url="+search)
@ -24,16 +33,9 @@
document.getElementById("img").setAttribute("src",imgBase64) document.getElementById("img").setAttribute("src",imgBase64)
document.getElementById("login").click() document.getElementById("login").click()
} }
function isWeixin () { function isWechat() {
let user= navigator.userAgent.toLowerCase(); return /MicroMessenger/i.test(window.navigator.userAgent);
if(user.match(/MicroMessenger/i)==="micromessenger") {
console.log('微信')
document.getElementById("wx").innerText = "检测到微信环境,请单击右上角选择浏览器打开跳转"
} else {
console.log('非微信')
}
} }
isWeixin()
load() load()
</script> </script>