安卓和IOS、微信 公用一个二维码
作者: thtomatic 分类: 前端 评论: [ 0 ] 条 浏览: [ 1100 ] 次
代码如下
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script>
/**
出来的链接大概是长这样的
http://xxxx.cn/243423.html?c=Q23DR32
*/
// c=Q23DR32是注册时扫描获取的邀请码。
// 这样加参数,后面的参数会被自动忽略,不会影响加载此网页
goDownload();
// 去下载
function goDownload() {
var u = navigator.userAgent, app = navigator.appVersion;
var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1;
var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
// 是安卓浏览器
if (isAndroid) {
window.location.href = 'http://xxxxxxx.cn/release/xxxx-release.apk'; // 跳安卓端下载地址
}
// 是iOS浏览器
if (isIOS) {
window.location.href = 'https://itunes.apple.com/cn/app/xxxxxxx/id1124348115?mt=8'; // 跳AppStore下载地址
}
// 是微信内部webView
if (is_weixn()) {
alert("请点击右上角按钮, 点击使用浏览器打开");
}
// 是PC端
if (IsPC()) {
window.location.href = 'http://www.xxxxxxx.cn/index.html'; // 公司主页
}
}
// 是微信浏览器
function is_weixn(){
var ua = navigator.userAgent.toLowerCase();
if(ua.match(/MicroMessenger/i)=="micromessenger") {
return true;
} else {
return false;
}
}
function IsPC() {
var userAgentInfo = navigator.userAgent;
var Agents = ["Android", "iPhone",
"SymbianOS", "Windows Phone",
"iPad", "iPod"];
var flag = true;
for (var v = 0; v < Agents.length; v++) {
if (userAgentInfo.indexOf(Agents[v]) > 0) {
flag = false;
break;
}
}
return flag;
}
</script>
</body>
</html>
放到服务器上获取这个页面的链接 生成二维码即可
版权所有:《thtomatic》 => 《安卓和IOS、微信 公用一个二维码》
本文地址:https://ask.mykeji.net/xhtml/170.html
除非注明,文章均为 《简单记录》 原创,欢迎转载!转载请注明本文地址,谢谢。
发表评论: