js打开应用

来源:互联网 发布:java三大程序结构 编辑:程序博客网 时间:2024/06/08 12:20
<a id="openApp"style="" href="http://itunes.apple.com/cn/app/id425349261?mt=8';
">APK客户端下载链接</a>


<script>
if(navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)){
document.getElementById('openApp').onclick = function(e) {
// 通过iframe的方式试图打开APP,如果能正常打开,会直接切换到APP,并自动阻止a标签的默认行为
// 否则打开a标签的href链接http://itunes.apple.com/cn/app/id333206289?mt=8
var ifrSrc = 'newsapp://';
if (!ifrSrc) {
return;
}
var ifr = document.createElement('iframe');
ifr.src = ifrSrc;
ifr.style.display = 'none';
document.body.appendChild(ifr);
setTimeout(function() {
document.body.removeChild(ifr);
}, 1000);
};
if (document.all) {
alert("all")
document.getElementById('openApp').click();
}
else {
var e = document.createEvent("MouseEvents");
e.initEvent("click", true, true);
document.getElementById("openApp").dispatchEvent(e);
}
}else if (navigator.userAgent.match(/android/i)) {
document.getElementById('openApp').onclick = function(e) {
// 通过iframe的方式试图打开APP,如果能正常打开,会直接切换到APP,并自动阻止a标签的默认行为
// 否则打开a标签的href链接
var ifrSrc = 'https://itunes.apple.com/cn/app/id333206289?mt=8';
if (!ifrSrc) {
return;
}
var ifr = document.createElement('iframe');
ifr.src = ifrSrc;
ifr.style.display = 'none';
document.body.appendChild(ifr);
setTimeout(function() {
document.body.removeChild(ifr);
}, 1000);
};
if (document.all) {
document.getElementById('openApp').click();
}
else {
var e = document.createEvent("MouseEvents");
e.initEvent("click", true, true);
document.getElementById("openApp").dispatchEvent(e);
}
}
</script>
0 0
原创粉丝点击