APP推广下载页,如何自动跳转各应用市场

7 篇文章 0 订阅

        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.com/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.com/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.com/app/xxxxxxx";
				} else if(ifr.src.indexOf('mimarket') > -1){
					window.location.href = "http://app.mi.com/details?id=你的应用包名&ref=search";
				}else {
					window.location.href = "https://a.app.qq.com/o/simple.jsp?pkgname=你的应用包名";
				}
			},1000);
        } else {
            window.location.href = "https://a.app.qq.com/o/simple.jsp?pkgname=你的应用包名";
        }
    }
}
</script>
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值