//html代码中 的 a 标签,以微信为例,默认的是调用weixin scheme,去打开本机的微信,如果没有则跳转到相应连接
<a href="weixin://" rel="external nofollow" class="btn-download">立即打开</a>
// 为btn-download 绑定事件,如果在500ms内,没有解析到协议,那么就会跳转到下载链接
var appstore, ua = navigator.userAgent;
if(ua.match(/Android/i)){
appstore = 'market://search?q=com.singtel.travelbuddy.android';
}
if(ua.match(/iphone|ipod|ipad/)){
appstore = "https://itunes.apple.com/cn/app/wei-xin/id414478124?mt=8&ign-mpt=uo%3D4";
}
function applink(fail){
return function(){
var clickedAt = +new Date;
// During tests on 3g/3gs this timeout fires immediately if less than 500ms.
setTimeout(function(){
// To avoid failing on return to MobileSafari, ensure freshness!
if (+new Date - clickedAt < 2000){
window.location = fail;
}
}, 500);
};
}
$('.icon-download, .btn-download')[0].onclick = applink(appstore);
// 页面中有div#iframe-box 用来插入生成的iframe,还是以微信为例
var ifm = document.createElement('iframe'), isInstalled;
ifm.style.display = 'none';
ifm.src = 'wixin://';
ifm.onload = function(e){
var e = e || window.event;
e.preventDefault();
}
ifm.onerror = function(){
//isInstalled = false;
alert(1);
}
document.getElementById('iframe-box').appendChild(ifm);
// 但这时的问题是,iframe的src成功解析到了协议,则会直接跳转,但是解析不到的话,也不会触发error事件,这个还要继续研究
// 可以把上面的代码,放到函数中,然后作为某个按钮的响应函数。
<meta name="apple-itunes-app" content="app-id=414478124" />
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有