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

用于deeplink的js方法(判断手机是否安装app)

2018-10-12 13:58 316 查看

代码功能:
判断手机/平板是否安装app
如果安装 则调用app的scheme,传入url当作参数,来做后续操作
如果没有安装 则跳转到app store/google play 下载app


(function() {
var openUrl = window.location.search;
try{
openUrl = openUrl.substring(1,openUrl.length);
}catch(e){

}
var isiOS = navigator.userAgent.match('iPad')
|| navigator.userAgent.match('iPhone')
|| navigator.userAgent.match('iPod'), isAndroid = navigator.userAgent
.match('Android'),isDesktop = !isiOS&&!isAndroid;
if (isiOS) {
setTimeout(function () { window.location = "itms-apps://itunes.apple.com/app/[name]/[id]?mt=8"; },25);
window.location = "[scheme]://[host]?url="+openUrl;
}else if(isAndroid){
window.location = "intent://[host]/"+"url="+openUrl+"#Intent;scheme=[scheme];package=[package_name];end";
}else{
window.location.href = openUrl;
}
})();

您可能感兴趣的文章:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: