首先来说二维码的生成,下载二维码有一个链接生成(常用的草料网站),要想实现二维码的在各个平台都能有效,这就需要我们判断设备系统(navigator.userAgent)下面直接上代码,只需更改链接上传服务器就可得到自己的二维码链接,通过草料即可生成多样式二维码!
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;
}
借鉴链接://www.greatytc.com/p/f9db096857c2作者:BOC