点击页面判断是否安装app并打开,否则跳转app store的方法
常常有这样的场景,咱们开发出来的APP需要进行推广,比如在页面顶部来一张大Banner图片,亦或一张二维码。但往往我们都是直接给推广图片加了一个下载链接(App Store中的)。所以咱们来模拟一下用户的操作步骤:
1、用户第一次访问宣传页面
a、点击Banner,进入到APP Store中对应的APP下载页
b、APP下载页中提示:安装;用户点击安装
c、安装完成后,APP下载页中提示:打开;用户继续点击打开
d、用户正常使用APP
2、用户第二次访问宣传页面
a、点击Banner,进入到APP Store中对应的APP下载页
b、APP下载页中提示:打开;用户直接点击打开
c、用户正常使用APP
3、用户第三次、第四次、...、第N次访问,操作步骤同2
能看出来,不管是点击Banner还是扫描二维码的方式,对于已经安装过APP的用户来说,这个体验都是非常糟糕的。
更优的体验是:点击Banner(或扫描二维码)后,程序判断当前系统是否已安装App,如果未安装,则自动跳转到App Store下载页;否则直接打开App。
在iOS上,要增加一个APP的大Banner,其实只需要在<head>标签内增加一个<meta>标签即可,格式如:
<meta name='apple-itunes-app' content='app-id=你的APP-ID'>
比如加一个百度贴吧的Native APP大Banner,用下面这串儿代码:
- <meta name='apple-itunes-app' content='app-id=477927812'>
而对于点击链接后,能否直接打开,可以通过下面的代码来实现。前提条件:你得知道你的APP对应的打开协议,如贴吧APP,协议为:com.baidu.tieba:// ,微信的:weixin:// ,and so on。。。
- <!-- a标签的链接,设置为对应的下载链接;点击打开的动作,在click事件中注册 -->
- <a href="https://itunes.apple.com/cn/app/id477927812" id="openApp">贴吧客户端</a>
- <script type="text/javascript">
- document.getElementById('openApp').onclick = function(e){
- // 通过iframe的方式试图打开APP,如果能正常打开,会直接切换到APP,并自动阻止a标签的默认行为
- // 否则打开a标签的href链接
- var ifr = document.createElement('iframe');
- ifr.src = 'com.baidu.tieba://';
- ifr.style.display = 'none';
- document.body.appendChild(ifr);
- window.setTimeout(function(){
- document.body.removeChild(ifr);
- },3000)
- };
- </script>
当然,如果你是设计成一张二维码,可以用下面这段代码:
- <!-- a标签的链接,设置为对应的下载链接;点击打开的动作,在click事件中注册 -->
- <a href="https://itunes.apple.com/cn/app/id477927812" id="openApp" style="display: none">贴吧客户端</a>
- <script type="text/javascript">
- document.getElementById('openApp').onclick = function(e){
- // 通过iframe的方式试图打开APP,如果能正常打开,会直接切换到APP,并自动阻止a标签的默认行为
- // 否则打开a标签的href链接
- var ifr = document.createElement('iframe');
- ifr.src = 'com.baidu.tieba://';
- ifr.style.display = 'none';
- document.body.appendChild(ifr);
- window.setTimeout(function(){
- document.body.removeChild(ifr);
- },3000)
- };
- document.getElementById('openApp').click();
要使用哪一种,就取决与你的实际场景了!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
if (navigator.userAgent.match(/android/i)) { // 通过iframe的方式试图打开APP,如果能正常打开,会直接切换到APP,并自动阻止a标签的默认行为 // 否则打开a标签的href链接 var isInstalled; //下面是安卓端APP接口调用的地址,自己根据情况去修改 var ifrSrc = 'cartooncomicsshowtwo://platformapi/startApp? type=0&id=${com.id}&phone_num=${com.phone_num}' ; var ifr = document.createElement( 'iframe' ); ifr.src = ifrSrc; ifr.style.display = 'none' ; ifr.onload = function() { // alert('Is installed.'); isInstalled = true ; alert(isInstalled); document.getElementById( 'openApp0' ).click();}; ifr.onerror = function() { // alert('May be not installed.'); isInstalled = false ; alert(isInstalled); } document.body.appendChild(ifr); setTimeout(function() { document.body.removeChild(ifr); }, 1000 ); } //ios判断 if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) { var isInstalled; //var gz = '{"comName":"${com.short_name}","comID":"${com.id}","comPhoneNum":"${com.phone_num}","type":"0"}'; //var jsongz =JSON.parse(gz); //下面是IOS调用的地址,自己根据情况去修改 var ifrSrc = 'Animation://?comName=${com.short_name}&comID=${com.id}&comPhoneNum=${com.phone_num}&type=0' ;var ifr = document.createElement( 'iframe' ); ifr.src = ifrSrc; ifr.style.display = 'none' ; ifr.onload = function() { // alert('Is installed.'); isInstalled = true ; alert(isInstalled); document.getElementById( 'openApp1' ).click();}; ifr.onerror = function() { // alert('May be not installed.'); isInstalled = false ; alert(isInstalled); } document.body.appendChild(ifr); setTimeout(function() { document.body.removeChild(ifr); }, 1000 ); } } |
转载请注明:Android开发中文站 » JS检测APP是否安装的情况
http://www.androidchina.net/2435.html
点击页面判断是否安装app并打开,否则跳转app store的方法的更多相关文章
- 【JS】点击页面判断是否安装app并打开,否则跳转下载的方法
应用场景 App产品在运营推广上有一个需求,就是要求可以让用户在访问我们的推广网页时,就可以判断出这个用户手机上是否安装了我们的App,如果安装了则可以直接在网页上打开,否则就引导用户前往下载.从而形 ...
- JavaBean组件<jsp:forward>动作<jsp:param>动作登录页面输入用户名和密码,然后进入检查页面判断是否符合要求,符合要求跳转到成功界面,不符合要求返回登录界面,显示错误信息。
JavaBean组件 JavaBean组件实际是一种java类.通过封装属性和方法成为具有某种功能或者处理某个业务的对象. 特点:1.实现代码的重复利用.2.容易编写和维护.3.jsp页面调用方便. ...
- 利用 html js判断 客户端是否安装了某个app 安装了就打开 否则跳转到gp
三种方式 方式一:简单的进行打开app,延时操作若未打开直接跳gp function isInstalled(){ var urlFrag = 'somepars'; var the_href = ' ...
- 在app中打开appStore中其他app
var str = "https://itunes.apple.com/cn/app/zhang-jiange-hao-tou-zi-ke/id402382976?mt=8"//这 ...
- JS如何实现点击页面内任意的链接均加参数跳转?
1.JS跳转页面参考代码 第一种: <script language="javascript" type="text/javascript"> wi ...
- h5页面判断微信端用浏览器打开代码
<div class="weixin-tip"> <p> <img src="img/live_weixin.png" alt=& ...
- js或jquery实现点击某个按钮或元素显示div,点击页面其他任何地方隐藏div
点击某个元素显示div,点击页面其他任何地方隐藏div,可用javascript和jquery两种方法实现: 一:javascript实现方法技巧<script>//定义stopPropa ...
- 根据appid跳到App Store某个APP的详情页
需求 本手机是否装了某个APP 示例百度appid 382201985 scheme BaiduSSO:// 1.是,直接打开百度APP 2.否,跳到App Store百度APP的详情页 NSStr ...
- web页面打开本地app(判断是否安装)
在应用宝中有APP申请链接: //是否可以打开App不可以跳则到下载页 $(".downNow button").on("click",function(){ ...
随机推荐
- 关于javascript的运动教程
一.javascript的匀速运动 关于物体的javascript匀速运动要点分析: 1.物体关于运动的时候,我们要打开定时器 2.打开定时器的时候我们记得要在停止的时候关闭定时器,同时应该注意的是一 ...
- 被误解的MVC和被神化的MVVM(转)
转载自:http://www.infoq.com/cn/articles/rethinking-mvc-mvvm 原文作者:唐巧 被误解的 MVC MVC 的历史 MVC,全称是 Model View ...
- [转]Pythoin中的Lambda表达式
引用自:http://www.cnblogs.com/evening/archive/2012/03/29/2423554.html 在学习python的过程中,lambda的语法时常会使人感到困惑, ...
- MySQL、MongoDB、Redis数据库Docker镜像制作
MySQL.MongoDB.Redis数据库Docker镜像制作 在多台主机上进行数据库部署时,如果使用传统的MySQL的交互式的安装方式将会重复很多遍.如果做成镜像,那么我们只需要make once ...
- css3学习--border
http://blog.sina.com.cn/s/blog_61671b520101gelr.html border-radius border-radius: 50px 20px;上下都是50px ...
- maven引入多个spring jar包中存在同名文件的问题
项目打包后执行报错:Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespaceht ...
- File 类
File 类:文件和目录(文件夹)路径名的抽象表现形式. 方法 1.创建功能 public boolean createNewFile():创建文件 public boolean mkdir():创建 ...
- PBR
https://iwantthatcake.wordpress.com/2012/02/22/real-time-radiosity-geometrics-enlighten/ http://www. ...
- UI
http://semantic-ui.com/introduction/getting-started.html
- 百度地图JavaScript API [一]
参考网址: http://developer.baidu.com/map/index.php?title=jspopular/guide/widget 1.申请密钥(ak) http://api.ma ...