1. 程式人生 > >JS實現安卓IOS公用一個二維碼

JS實現安卓IOS公用一個二維碼

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;

}