js结合schema实现外部网页点击APP下载按钮,已安装的话打开APP,未安装跳转到下载页
来源:互联网 发布:大鱼海棠影评知乎 编辑:程序博客网 时间:2024/06/09 17:59
项目经常有APP分享出去的页面,点击下方的按钮时要求如果安装了APP,打开APP并跳转到相应页面,如果未安装就跳转到下载页面。
如图
html代码
<div >
<a href="javascript:void(0)" id="btn_download ">
下载APP
</a>
</div>
<div class="isweixin-top hide p26 w-font pal6 pat3"><!--这里是在微信或Android的QQ里不能跳转出来,需要提示在浏览器中打开-->
<div class="wxword widper64"></div>
</div>
<iframe src="about:blank" id="iframe" hidden></iframe><!--ios需要写一个iframe-->
脚本代码
var btn_download = $('#btn_download');
var ua = window.navigator.userAgent.toLowerCase();
var isweixin = navigator.userAgent.toLowerCase().match(/micromessenger/i) != null;
var isqq = navigator.userAgent.toLowerCase().indexOf("qq/") > -1;
var isweibo = ua.match(/weibo/i) == "weibo";
if (isweixin || isweibo) {
$('#btn_download').click(function () {
$('.isweixin-top').removeClass('hide');
});
if (/android/i.test(navigator.userAgent)) { //如果是Android微信浏览器
$('.isweixin-top').find('.wxword').text('点击右上角,选择“在浏览器中打开”');
} else if (/ipad|iphone|mac/i.test(navigator.userAgent)) { //如果是ios微信浏览器
$('.isweixin-top').find('.wxword').text('点击右上角,选择“在safari中打开”');
}
} else {
if (/android/i.test(navigator.userAgent)) {
if (!isweixin && !isqq) {
btn_download.attr('href', "intent://edu-yun.com?start_type=7&type=2&course_id=" + course_id);
btn_download.click(function () {
openandIndex()
})
} else if (isqq) {
// btn_android.removeClass('hide');
$('.isweixin-top').find('.wxword').text('点击右上角,选择“用浏览器打开”');
btn_download.click(function () {
$('.isweixin-top').removeClass('hide');
$('.isweixin-top').css('background-color', '#12b7f5');
})
}
} else if (/ipad|iphone|mac/i.test(navigator.userAgent)) {
if (!isweixin && !isqq) {
// btn_ios.removeClass('hide');
btn_download.click(function () {
window.location.href = "CenturyGuard://edu-yun.com?start_type=7&type=2&course_id=" + course_id;
openiosIndex()
})
} else if (isqq) {
// btn_ios.removeClass('hide');
btn_download.attr('href', 'CenturyGuard://edu-yun.com?start_type=7&type=2&course_id=' + course_id);
btn_download.click(function () {
openiosIndex()
});
}
}
}
function openandIndex() {
var t = setTimeout(function () {
window.location.href = "http://a.app.qq.com/o/simple.jsp?pkgname=yilanTech.EduYunClient" //您的APP下载地址,这里只是举个例子
}, 3000);
setTimeout(function () {
clearTimeout(t)
}, 3500)
}
function openiosIndex() {
var t = setTimeout(function () {
window.location.href = " https://itunes.apple.com/cn/app/shi-ji-shou-hu/id1067211489?l=zh&mt=8" //您的APP下载地址,这里只是举个例子
}, 1500);
setTimeout(function () {
clearTimeout(t)
}, 1500)
}
需要说明的是上文中的:
"intent://edu-yun.com?start_type=7&type=2&course_id=" + course_id 其中 intent://edu-yun.com 是我们这项目Android端给的schema,不同项目不一样啊,要问原生的小伙伴要。
CenturyGuard://edu-yun.com?start_type=7&type=2&course_id=" + course_id 其中 CenturyGuard://edu-yun.com 是ios小伙伴给我的schema。
问号后面的参数就是根据外部网页需要定位到APP的哪个位置, start_type是和3端(android,ios,服务器)定义的是原生端分享出去的还是web端分享出去的,type是哪个功能,course_id是改功能模块的的哪条数据。问号后面的都是根据各自项目不同而不同,主要是为了定位到相应的页面。
- js结合schema实现外部网页点击APP下载按钮,已安装的话打开APP,未安装跳转到下载页
- Js判定移动端是否安装app,若已安装,则打开,未安装则跳转到下载页面
- js判断是否安装某个app,安装了就打开app,未安装跳转到下载页面
- js判断本地是否安装app,未安装去下载,已安装打开本地的app
- JS实现点击网页判断是否安装app并打开否则跳转app store
- 点击导航按钮后进入百度地图app,如果手机没有安装的话,就跳转到AppStore
- 网页判断判断是否安装APP并启动,没有安装就跳转到下载页面
- Android&iOS:如何在外部启动app(若有安裝APP, 则自动启动app(使用 URL Schema), 若没有安装, 则询问是不是到应用市场下载)
- 在UC浏览器打开链接唤醒app,如果没有安装该app,则跳转到appstore下载该应用
- web网页引导app启动或下载 有安装则启动app,未安装或启动失败引导下载
- JS实现点击网页判断是否安装App
- 在线安装ipa ,跨过app-store / JSP中实现判断客户端手机类型并跳转到app下载页面
- android网页调起app并且传参, 网页点击高速下载跳转app
- 致远App下载安装
- iOS——由app跳转到AppStore下载app或者调转到某一个网页
- ios 点击网页页面判断是否安装app并打开
- DownloadManager实现下载、安装更新app功能
- Android基础--下载安装app,会提示完成和打开,点击打开运行所产生的问题
- 欢迎使用CSDN-markdown编辑器
- 微信点餐小程序,左右菜单联动,菜单和购物车数量同步加减功能
- BOM中的三种提示窗口
- MySQL日期数据类型、时间类型使用总结
- [资源分享] Android Studio 和 Eclipse 中获取SHA1详解
- js结合schema实现外部网页点击APP下载按钮,已安装的话打开APP,未安装跳转到下载页
- 图片轮播的实现
- MQTT——java简单测试(二)
- PHP中遍历数组有三种常用的方法
- 前端资料整合
- 史上最简单的SpringCloud教程 | 第九篇: 服务链路追踪(Spring Cloud Sleuth)
- Shell查找与替换
- 快速幂模板
- java基础总结(二)-----》java三大特性/原则------继承