admin管理员组文章数量:1624794
APP推广下载页,起初的做法是自己提供一个下载地址,用户下载安装之后检测更新,获取最新版本。后来老板可能觉得这样不够智能,有点麻烦,就要改成自动跳转应用市场,直接安装最新版本的,这才有了下面的代码段(两年前的代码了,今天有人在群里问,就拿出来总结下,勿喷)。
总体就是一个下载页链接,可以提供链接二维码,不管用户通过什么方式打开,都要实现自动跳转应用市场功能,微信端由于微信内部限制,可以判断下用户的浏览环境,若是微信浏览器打开可以提示用户复制链接地址,用浏览器打开即可。
<script type="text/javascript">
var ifr = document.createElement('iframe');
ifr.style.display = 'none';
$(function () {
var flag = getPlatform();
if (flag == 1) {
android_download();
}
if (flag == 2) {
ios_download();
}
});
function getPlatform() {
var result = 0;
var url = window.location.search;
if (url.indexOf("?") != -1) {
result = url.substr(url.indexOf("=") + 1);
}
return result;
}
var ua = navigator.userAgent.split("(")[1].split(")")[0];
var brand = "";
var phone = [/IPHONE/gi, /huawei/gi, /mi/gi, /v1/gi, /OPPO/gi, /vivo/gi, /pcg/gi, /vivo/gi,];
if (phone[0].test(ua)) {
brand = "iPhone";
window.location.href = "https://apps.apple/cn/app/xxxxxxxxxx";
} else if (phone[1].test(ua)) {
brand = "HUAWEI";
ifr.src = 'appmarket://details?id=你的应用包名';
} else if (phone[2].test(ua)) {
brand = "小米";
ifr.src = 'mimarket://details?id=你的应用包名';
} else if (phone[3].test(ua) || phone[5].test(ua) || phone[7].test(ua)) {
brand = "vivo";
ifr.src = 'vivomarket://details?id=你的应用包名';
} else if (phone[4].test(ua) || phone[6].test(ua)) {
brand = "OPPO";
ifr.src = 'oppomarket://details?packagename=你的应用包名';
} else {
brand = "Android";
ifr.src = '';
}
function ios_download() {
window.location.href = "https://apps.apple/cn/app/xxxxxxx";
}
function is_weixin() {
var ua = navigator.userAgent.toLowerCase();
if (ua.match(/MicroMessenger/i) == "micromessenger") {
return true;
} else {
return false;
}
}
function android_download() {
if (is_weixin()) {
ICEICE(".weixin_notice").style.display = "block";
var url = window.location.href;
if (url.indexOf("source") <= 0) {
history.pushState("", "", url + "?source=1");
}
} else {
if (ifr.src.indexOf('hgxx') > -1) {
document.body.appendChild(ifr);
setTimeout(function() {
if(ifr.src.indexOf('appmarket') > -1){
window.location.href = "https://appstore.huawei/app/xxxxxxx";
} else if(ifr.src.indexOf('mimarket') > -1){
window.location.href = "http://app.mi/details?id=你的应用包名&ref=search";
}else {
window.location.href = "https://a.app.qq/o/simple.jsp?pkgname=你的应用包名";
}
},1000);
} else {
window.location.href = "https://a.app.qq/o/simple.jsp?pkgname=你的应用包名";
}
}
}
</script>
版权声明:本文标题:APP推广下载页,如何自动跳转各应用市场 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dianzi/1728909931a1179091.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论