<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的更多相关文章

  1. h5页面唤起app(iOS和Android),没有安装则跳转下载页面

    浏览器和app没有通信协议,所以h5不知道用户的手机释放安装了app.因此只能是h5去尝试唤起app,若不能唤起,引导用户去下载我们的app. 微信里屏蔽了 schema 协议,如果在微信中打开h5, ...

  2. Ionic – 强大的 HTML5 Mobile App 开发框架

    Ionic 是一个强大的 HTML5 应用程序开发框架,可以帮助您使用 Web 技术,比如 HTML.CSS 和 Javascript 构建接近原生体验的移动应用程序.Ionic 主要关注外观和体验, ...

  3. HTML5手机APP开发入(5)

    HTML5手机APP开发入(5) 回顾一下 HTML5手机APP开发入(4) 如何自定义Component,directive HTML5手机APP开发入(3) 如何实现MVC的代码重构,自定义一个P ...

  4. HTML5手机APP开发入(4)

    HTML5手机APP开发入(4) 课程内容 完成一个自定义的Component用来展现通讯录用户的明细信息如下图 http://bootsnipp.com/snippets/featured/prof ...

  5. HTML5手机APP开发入(3)

    HTML5手机APP开发入(3) 课程内容: 按照AngularJs MVC框架进行代码重构,新建一个DataService服务类使用SQLite插件实现储存对通讯录的本地存储. 涉及的知识点: An ...

  6. HTML5手机APP开发入门(2)

    HTML5手机APP开发入门(2) 课程内容 使用IonicFramework v2 + angular 2 完成一个简单的联系人列表的操作,有三个页面: ListPage,DetailPage,Ad ...

  7. HTML5手机APP开发入门(1)

    HTML5手机APP开发入门(1) 开发框架 Ionicframework V2 + Angular 2 具体内容可以参考一下网站 http://ionicframework.net/ http:// ...

  8. h5唤起APP并检查是否成功

    // 检查app是否打开 function checkOpen(cb) { const clickTime = +(new Date()); function check(elsTime) { if ...

  9. H5 唤起 APP的解决方案

    H5 页面唤起APP或跳转到下载APP的某个链接地址.总结如下: 在 IOS 中, 系统版本在 8 以下时,可以监听页面的 pagehide / visibilitychange 事件. 系统版本大于 ...

随机推荐

  1. kafka--- consumer 消费消息

    1. consumer API kafka 提供了两套 consumer API: 1. The high-level Consumer API 2. The SimpleConsumer API 其 ...

  2. JavaScript中Global、Math、Date对象的常用方法

    JavaScript当中Global.Math.Date类型常用方法如下: /* js 中 Global对象 是一个不存在的对象,它里面的方法可以调用 常用方法: 1 encodeURI 对uri进行 ...

  3. super函数的作用

    super函数的作用super().__init__()当子类重写父类的方法时,会覆盖父类方法,super此举是保留父类 如果属性名跟方法名相同,属性会覆盖方法 方法必须要有实例才能被调用,这叫做绑定

  4. Menu-右键弹出菜单

    #右键弹出菜单 from tkinter import * root=Tk() def callback(): print('我被调用了') menubar =Menu(root) menubar.a ...

  5. linux(centos)常用命令

    原文:https://blog.csdn.net/zhangzhikaixinya/article/details/44538571 1.查看当前所在路径:pwd 2.新建文件夹www:mkdir w ...

  6. fiddler实现手机抓包

    对fiddler相关配置 1.允许fiddler捕获http协议,打开fiddler客户端,菜单框选择Tools->Options->HTTPS,勾选图中三项 2.允许远程连接,Tools ...

  7. winform中的数据绑定

    1. 简单的数据绑定 例1 using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings[& ...

  8. [C#]200 行代码使用 C# 实现区块链

    文章原文来自:Code your own blockchain in less than 200 lines of Go!,原始文章是通过 Go 语言来实现自己的区块链的,这里我们参照该文章来使用 C ...

  9. [LeetCode] Maximum Vacation Days 最大化休假日

    LeetCode wants to give one of its best employees the option to travel among N cities to collect algo ...

  10. [LeetCode] Detect Capital 检测大写格式

    Given a word, you need to judge whether the usage of capitals in it is right or not. We define the u ...