HTML5 唤起 APP
<p><a href="xxx://app/question/95">点击跳转,直接回帖报名</a></p>
/* global navigator, document, window */
var UA = {
App: navigator.userAgent.indexOf('naitangApp') >= 0,
WeiXin: navigator.userAgent.indexOf('MicroMessenger') >= 0,
Android: navigator.userAgent.indexOf('Android') >= 0,
iPhone: navigator.userAgent.indexOf('iPhone') >= 0
}
var timeout
function replaceSchema(href) {
var schema = [
['xxx://app/question/', 'http://www.xxx.com/question/']
]
var len = schema.length
for (var i = 0; i < len; i += 1) {
href = href.replace(schema[i][0], schema[i][1])
}
return href
}
document.querySelector('body').addEventListener('click', function(e) {
var tg = (window.event) ? e.srcElement : e.target
while (tg.nodeName.toUpperCase() !== 'BODY') {
if (tg && tg.nodeName.toUpperCase() === 'A') {
var href = tg.getAttribute('href')
if (href.indexOf('naitang://') === 0) {
e.preventDefault()
if (UA.App) {
window.location.href = href
} else if (UA.WeiXin) {
window.location.href = 'http://a.app.qq.com/o/simple.jsp?pkgname=com.xxxxxx'
} else if (UA.Android) {
window.location.href = href
timeout = setTimeout(function() {
window.location.href = 'http://a.app.qq.com/o/simple.jsp?pkgname=com.xxxxxx'
}, 1000)
} else if (UA.iPhone) {
window.location.href = href
timeout = setTimeout(function() {
window.location.href = 'itms-apps://itunes.apple.com/cn/app/nai-tang/id00000000?mt=8'
}, 1000)
} else {
var pchref = tg.getAttribute('data-pc')
href = pchref ? pchref : replaceSchema(href)
window.location.href = href
}
}
break
} else {
tg = tg.parentNode
}
}
}, false)
function onVisibilityChanged() {
var hidden = document.hidden || document.webkitHidden
if (hidden && timeout) {
window.clearTimeout(timeout)
}
}
document.addEventListener('visibilitychange', onVisibilityChanged, false)
HTML5 唤起 APP的更多相关文章
- h5页面唤起app(iOS和Android),没有安装则跳转下载页面
浏览器和app没有通信协议,所以h5不知道用户的手机释放安装了app.因此只能是h5去尝试唤起app,若不能唤起,引导用户去下载我们的app. 微信里屏蔽了 schema 协议,如果在微信中打开h5, ...
- Ionic – 强大的 HTML5 Mobile App 开发框架
Ionic 是一个强大的 HTML5 应用程序开发框架,可以帮助您使用 Web 技术,比如 HTML.CSS 和 Javascript 构建接近原生体验的移动应用程序.Ionic 主要关注外观和体验, ...
- HTML5手机APP开发入(5)
HTML5手机APP开发入(5) 回顾一下 HTML5手机APP开发入(4) 如何自定义Component,directive HTML5手机APP开发入(3) 如何实现MVC的代码重构,自定义一个P ...
- HTML5手机APP开发入(4)
HTML5手机APP开发入(4) 课程内容 完成一个自定义的Component用来展现通讯录用户的明细信息如下图 http://bootsnipp.com/snippets/featured/prof ...
- HTML5手机APP开发入(3)
HTML5手机APP开发入(3) 课程内容: 按照AngularJs MVC框架进行代码重构,新建一个DataService服务类使用SQLite插件实现储存对通讯录的本地存储. 涉及的知识点: An ...
- HTML5手机APP开发入门(2)
HTML5手机APP开发入门(2) 课程内容 使用IonicFramework v2 + angular 2 完成一个简单的联系人列表的操作,有三个页面: ListPage,DetailPage,Ad ...
- HTML5手机APP开发入门(1)
HTML5手机APP开发入门(1) 开发框架 Ionicframework V2 + Angular 2 具体内容可以参考一下网站 http://ionicframework.net/ http:// ...
- h5唤起APP并检查是否成功
// 检查app是否打开 function checkOpen(cb) { const clickTime = +(new Date()); function check(elsTime) { if ...
- H5 唤起 APP的解决方案
H5 页面唤起APP或跳转到下载APP的某个链接地址.总结如下: 在 IOS 中, 系统版本在 8 以下时,可以监听页面的 pagehide / visibilitychange 事件. 系统版本大于 ...
随机推荐
- 如何在命令行中让python2和python3同存
初学python,你可能同时安装了python2和3.在我们安装好python之后,我们会面临这样一个问题,在命令行输入"python",可能会出错,或者只能调用其中一个版本,py ...
- Maven使用本地jar包(两种方式)
有些项目会用到一些Maven库上没有的jar包,这就需要我们自己引入了 这种情况有两种办法: 第一种方式,在pom文件中引用时使用本地路径: 首先把jar包放到项目中: 然后在pom文件中引入: &l ...
- JDK1.8源码(七)——java.util.HashMap 类
本篇博客我们来介绍在 JDK1.8 中 HashMap 的源码实现,这也是最常用的一个集合.但是在介绍 HashMap 之前,我们先介绍什么是 Hash表. 1.哈希表 Hash表也称为散列表,也有直 ...
- 发布你的程序包到Nuget
1.新建一个.NET Standard 的类库项目 2.选择项目熟悉,在 package 栏目下填写我们的nuget包信息 3.选择我们的项目,点击"Pack" 打包 主要注意的是 ...
- [LeetCode] Sum of Square Numbers 平方数之和
Given a non-negative integer c, your task is to decide whether there're two integers a and b such th ...
- SSH执行hql报错:Caused by: org.hibernate.hql.ast.QuerySyntaxException: user is not mapped [from user where username = ?]
报错信息: ERROR Dispatcher:38 - Exception occurred during processing request: user is not mapped [from u ...
- day 1——字典树练习
cojs 173. 词链 ★☆ 输入文件:link.in 输出文件:link.out 简单对比时间限制:1 s 内存限制:128 MB [问题描述]给定一个仅包含小写字母的英文单词表, ...
- [NOIp 2014]联合权值
Description 无向连通图G 有n 个点,n - 1 条边.点从1 到n 依次编号,编号为 i 的点的权值为W i ,每条边的长度均为1 .图上两点( u , v ) 的距离定义为u 点到v ...
- [HOJ2634] How to earn more 最大权闭合子图
Xiao Ming is an expert in computer science and technology, so he can get a lot of projects every mon ...
- ●BZOJ 3123 [Sdoi2013]森林
题链: http://www.lydsy.com/JudgeOnline/problem.php?id=3123 题解: 主席树,在线,启发式合并 简单版(只有询问操作):[2588: Spoj 10 ...