您的位置:首页 > 移动开发

在html页面中js判断app是否安装并直接打开

2015-11-25 09:29 786 查看
<script type="text/javascript">
document.getElementById('openApp').onclick = function(e){
// 通过iframe的方式试图打开APP,如果能正常打开,会直接切换到APP,并自动阻止a标签的默认行为
// 否则打开a标签的href链接
var agent = navigator.userAgent.toLowerCase() ;
var version;
if(agent.indexOf("like mac os x") > 0){
//ios
var regStr_saf = /os [\d._]*/gi ;
var verinfo = agent.match(regStr_saf) ;
version = (verinfo+"").replace(/[^0-9|_.]/ig,"").replace(/_/ig,".");
}

var version_str = version+"";
if(version_str != "undefined" && version_str.length >0){
version=version.substring(0,1);
if(version > 8){
location.href = 'com.ywwy.MaiDian3://'+"<?=$shop['id']?>";
window.setTimeout(function(){
location.href = 'https://itunes.apple.com/cn/app/id1052060244';
},300)

} else{
var ifr = document.createElement('iframe');
ifr.src = 'com.ywwy.MaiDian3://'+"<?=$shop['id']?>";
ifr.style.display = 'none';
document.body.appendChild(ifr);
window.setTimeout(function(){
location.href = 'https://itunes.apple.com/cn/app/id1052060244';
},300)
}
}
};
</script>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  判断本地app