概述
var hasOwnProp = Object.prototype.hasOwnProperty;
var brands = {
"IPHONE": "IPHONE|IPAD|IPOD|IOS",
"OPPO": "OPPO",
"VIVO": "VIVO",
"HONOR": "HONOR",
"HUAWEI": "HUAWEI",
"XIAOMI": "XIAOMI|REDMI",
"360": "1801-A01|1707-A01|1509-A00",
"SAMSUNG": "SAMSUNG"
}
var userAgent = window.navigator.userAgent.toUpperCase();
var is_weixin = (function () {
if (userAgent.match(/MicroMessenger/i) == "MICROMESSENGER") {
return true;
} else {
return false;
}
})();
var is_dingtalk = (function () {
if (userAgent.match(/DingTalk/i) == "DINGTALK") {
return true;
} else {
return false;
}
})();
for (var key in brands) {
if (hasOwnProp.call(brands, key)) {
brands[key] = new RegExp(brands[key], 'i');
}
}
/**
* 获取系统名称,安卓或者ios
*/
function getOS() {
if (userAgent.indexOf("ANDROID") > -1) {
return "ANDROID";
} else if (userAgent.indexOf("IPHONE") > -1) {
return "IOS";
}
}
/**
* 获取设备品牌
*/
function getBrand() {
var result = [];
for (var key in brands) {
if (hasOwnProp.call(brands, key)) {
if (brands[key].test(userAgent)) {
result.push(key);
}
}
}
return result[0];
}
var os = getOS();
var brand = getBrand();
function downloadApp(brand) {
if (os === "IOS") {
window.location.href = "https://itunes.apple.com/cn/app/id值";
return;
}
if (is_weixin || is_dingtalk) {
document.querySelector("#tip").style.display = "block";
return;
}
switch (brand) {
case "HONOR":
window.location.href = 'intent://details?id=apk的包名#Intent;package=com.huawei.appmarket;scheme=market;end;';
break;
case "HUAWEI":
case "OPPO":
window.location.href = "market://details?id=apk的包名";
break;
case "XIAOMI":
window.location = 'intent://details?id=apk的包名#Intent;package=com.xiaomi.market;scheme=market;end;';
break;
//case "VIVO":
// window.location.href = 'intent://details?id=apk的包名#Intent;package=com.bbk.appstore;scheme=market;end;';
// break;
//case "SAMSUNG":
// window.location.href = "http://www.samsungapps.com/appquery/appDetail.as?appId=apk的包名";
// break;
//case "360":
// window.location.href = 'intent://details?id=apk的包名#Intent;package=com.qihoo.appstore;scheme=market;end;';
// break;
default:
window.location.href = "https://a.app.qq.com/o/simple.jsp?pkgname=apk的包名";
break;
}
}
window.onload = function () {
downloadApp(brand);
document.querySelector("#download").addEventListener("tap", function () {
downloadApp(brand);
});
document.querySelector("#tip").addEventListener("tap", function () {
this.style.display = "none";
});
}
最后
以上就是懦弱水池为你收集整理的根据手机品牌跳转不同的应用市场的全部内容,希望文章能够帮你解决根据手机品牌跳转不同的应用市场所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复