admin管理员组文章数量:1606473
最近看到一篇文章介绍如何实现,ios和android 使用同一个二维码自动实现跳转下载链接;最近公司项目正好也遇到了同样需求,在此笔记一下:
希望iOS和安卓使用一个二维码,让扫描的机器自己识别操作系统实现跳转到相应的下载链接。比如iPhone用微信进行扫描就让他跳转appStore的下载页面,安卓机器使用微信扫描就直接跳浏览器下载。但是这二维码还有一个需求就是,用户已经下载了这个app,当用户打开app进入到注册页面时,再次扫描这个二维码时,自动填写邀请码进行注册。
*使用js实现,其实代码非常简单.
*使用时直接拷贝代码,改掉相应的链接就好。
*PS:该链接在微信环境打开时还是需要手动跳转到手机的浏览器才能跳到下载页面,因为微信内的webView比较特别,所以写了一个alert引导用户打开浏览器。
*如果有更好的解决方案希望给我留言或者发邮箱(zl570932980@163)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script>
/**
出来的链接大概是长这样的
http://xxx/1234.html?c=Q23AD12
*/
// 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/release/xxxx-release.apk'; // 跳安卓端下载地址
}
// 这里是iOS浏览器
if (isIOS) {
window.location.href = 'https://itunes.apple/cn/app/xxxxxxx/id1124348115?mt=8'; // 跳AppStore下载地址
}
// 是微信内部webView
if (is_weixn()) {
alert("请点击右上角按钮, 点击使用浏览器打开");
}
// 是PC端
if (IsPC()) {
window.location.href = 'http://www.xxxxxxx/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>
版权声明:本文标题:iOS和安卓共用同一个二维码实现跳转下载链接 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dongtai/1728500280a1161093.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论