//html部分
<a id="call-app" href="javascript:void(0);" style="display: inline-block;float:right;">
<input id="download-app" type="hidden" name="storeurl" value="https://android.myapp.com/myapp/detail.htm?apkName=com.xunmeng.pinduoduo&ADTAG=mobile">
<div class="intoR">
<span>立即进入</span>
</div>
</a>
//js部分
var u = navigator.userAgent;
var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
// 更换input的value决定跳转到哪个下载应用页面
if (!isAndroid) {
document.getElementById('download-app').value = 'https://apps.apple.com/cn/app/id1229469444';
} else {
document.getElementById('download-app').value = 'https://android.myapp.com/myapp/detail.htm?apkName=com.xunmeng.pinduoduo&ADTAG=mobile';
}
var ua = navigator.userAgent.toLowerCase();
var t;
var config = {
scheme_IOS: 'pinduoduo://com.xunmeng.pinduoduo',
scheme_Adr: 'pinduoduo://com.xunmeng.pinduoduo/duo_coupon_landing.html?goods_id=22601078025&pid=8592112_101958852&cpsSign=CC_191014_8592112_101958852_aa2fe711d970ccb958d855ad24c468b6&duoduo_type=2',
download_url: document.getElementById('download-app').value,
timeout: 600
};
function openclient() {
var startTime = Date.now();
var ifr = document.createElement('iframe');
// 创建ifram并指定src
ifr.src = ua.indexOf('os') > 0 ? config.scheme_IOS : config.scheme_Adr;
ifr.style.display = 'none';
document.body.appendChild(ifr);
var t = setTimeout(function () {
var endTime = Date.now();
if (!startTime || endTime - startTime < config.timeout + 200) {
window.location = config.download_url;
} else {
}
}, config.timeout);
window.onblur = function () {
clearTimeout(t);
}
}
window.addEventListener("DOMContentLoaded", function () {
document.getElementById("call-app").addEventListener('click',
openclient, false);
}, false);