js 唤起APP
常常有这样的场景,咱们开发出来的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); }} |
js 唤起APP的更多相关文章
- 【js】手机浏览器端唤起app,没有app就去下载app 的方法
这种功能的作用: 1.一般公司有自己的app,而app是需要不断有新用户涌入才能持续运营,达到不错的收入.就需要使用这种方式进行引入新的用户. 2.一些内容在网页端体验不好,或者一些功能需要app内才 ...
- 通过JS下载 or 唤起App
判断唤起app的连接是否在WeChat中打开 let isWeiXin = navigator.userAgent.toLowerCase().indexOf('micromessenger') != ...
- h5页面唤起app(iOS和Android),没有安装则跳转下载页面
浏览器和app没有通信协议,所以h5不知道用户的手机释放安装了app.因此只能是h5去尝试唤起app,若不能唤起,引导用户去下载我们的app. 微信里屏蔽了 schema 协议,如果在微信中打开h5, ...
- H5唤起app
H5唤起app 1.判断是否在微信中打开 无论是在哪个平台的客户端Android/IOS,在微信的平台上访问都有一个问题,那就是无法启动客户端,这是微信为了安全性考虑的限制,android这边屏蔽sc ...
- 如何应用前端技术唤起app及判断用户来源及与原生交互的原理
做唤起时需要native端进行配合, h5唤起app这种需求是常见的.在移动为王的时代,h5在app导流上发挥着重要的作用. 目前我们采用的唤起方式是url scheme(iOS,Android平台都 ...
- H5如何实现唤起APP
前言 写过hybrid的同学,想必都会遇到这样的需求,如果用户安装了自己的APP,就打开APP或跳转到APP内某个页面,如果没安装则引导用户到对应页面或应用商店下载.这里就涉及到了H5与Native之 ...
- h5唤起APP并检查是否成功
// 检查app是否打开 function checkOpen(cb) { const clickTime = +(new Date()); function check(elsTime) { if ...
- H5 唤起 APP的解决方案
H5 页面唤起APP或跳转到下载APP的某个链接地址.总结如下: 在 IOS 中, 系统版本在 8 以下时,可以监听页面的 pagehide / visibilitychange 事件. 系统版本大于 ...
- h5移动网页唤起App
最近这个困惑了很久,不断的有一些坑,目前还有疑问关于iOS唤起无效时会出现弹框的问题,这个最后再说 1.首先可能需要判断当前浏览器的来源(目前开发的App还没有上架,所以针对腾讯出品的大家广为人知的微 ...
随机推荐
- Nginx安装与使用 及在redhat 中的简单安装方式
首先说下在redhat中的安装方法, 正常安装nginx 需要安装很多的依赖,最后再安装nginx,而且很容易出错. 在nginx官方上有这么一段描述: Pre-Built Packages for ...
- vivadio关联notepad++的关键式
D:\Program Files\Notepad++\notepad++.exe +[line number] [file name]
- ubuntu LAMP的安装
1.安装 Apache 1.打开终端 2. 输入以下命令 sudo apt-get install apache2 3. 如果没有sudo 权限,需要输入密码. 2.测试 Apache 为了确定安装是 ...
- Fiddler 抓包工具总结【转载】
原博主连接在文章底部 Fiddler是一个蛮好用的抓包工具,可以将网络传输发送与接受的数据包进行截获.重发.编辑.转存等操作.也可以用来检测网络安全.反正好处多多,举之不尽呀!当年学习的时候也蛮费劲, ...
- 巧用call,appl有 根据对象某一属性求最大值
查找对象数组中某属性的最大最小值的快捷方法 例如要查找array数组中对象的value属性的最大值 var array=[ { "index_id": 119, "are ...
- Java Web(十二) JavaMail发送邮件
发送邮件的原理 概叙 邮件服务器: 要在 Internet 上提供电子邮件功能,必须有专门的电子邮件服务器.例如现在 Internet 很多 提供邮件服务的厂商:sina.sohu.163 等等他们都 ...
- 【框架】Testng用例失败自动重跑(五)
arrow是testng的一个扩展插件,参考arrow的源代码 1.新建一个工程,结果如图: 2.RetryListener.java的代码 package com.netease.qa.testng ...
- RBAC功能模块
- Win10系列:UWP界面布局基础7
2.附加属性 有一些XAML元素,其自身的属性大多是在其它的元素中声明和使用的,该元素本身却很少使用,这些在其他元素中声明和使用的属性被称为附加属性(Attached Properties).附加属性 ...
- owin启动事项
在上下文中找不到 owin.Environment 项 owin没有启动. 尝试加载应用时出现了以下错误.- 找不到包含 OwinStartupAttribute 的程序集 startup类不是通过v ...