HTML5 唤起 APP

【HTML5 唤起 APP】知识养成了思想,思想同时又在融化知识。这篇文章主要讲述HTML5 唤起 APP相关的知识,希望能为你提供帮助。

< p> < a href="xxx://app/question/95"> 点击跳转,直接回帖报名< /a> < /p>

1 /* global navigator, document, window */ 2 3 var UA = { 4App: navigator.userAgent.indexOf(‘naitangApp‘) > = 0, 5WeiXin: navigator.userAgent.indexOf(‘MicroMessenger‘) > = 0, 6android: navigator.userAgent.indexOf(‘Android‘) > = 0, 7iPhone: navigator.userAgent.indexOf(‘iPhone‘) > = 0 8 } 9 var timeout 10 function replaceSchema(href) { 11var schema = [ 12[‘xxx://app/question/‘, ‘http://www.xxx.com/question/‘] 13] 14var len = schema.length 15for (var i = 0; i < len; i += 1) { 16href = https://www.songbingjia.com/android/href.replace(schema[i][0], schema[i][1]) 17} 18return href 19 } 20 document.querySelector(‘body‘).addEventListener(‘click‘, function(e) { 21var tg = (window.event) ? e.srcElement : e.target 22while (tg.nodeName.toUpperCase() !== ‘BODY‘) { 23if (tg & & tg.nodeName.toUpperCase() === ‘A‘) { 24var href = tg.getAttribute(‘href‘) 25if (href.indexOf(‘naitang://‘) === 0) { 26e.preventDefault() 27if (UA.App) { 28window.location.href = href 29} else if (UA.WeiXin) { 30window.location.href = ‘http://a.app.qq.com/o/simple.jsp?pkgname=com.xxxxxx‘ 31} else if (UA.Android) { 32window.location.href = href 33timeout = setTimeout(function() { 34window.location.href = ‘http://a.app.qq.com/o/simple.jsp?pkgname=com.xxxxxx‘ 35}, 1000) 36} else if (UA.iPhone) { 37window.location.href = href 38timeout = setTimeout(function() { 39window.location.href = ‘itms-apps://itunes.apple.com/cn/app/nai-tang/id00000000?mt=8‘ 40}, 1000) 41} else { 42var pchref = tg.getAttribute(‘data-pc‘) 43href = pchref ? pchref : replaceSchema(href) 44window.location.href = href 45} 46} 47break 48} else { 49tg = tg.parentNode 50} 51} 52 }, false) 53 function onVisibilityChanged() { 54var hidden = document.hidden || document.webkitHidden 55if (hidden & & timeout) { 56window.clearTimeout(timeout) 57} 58 } 59 document.addEventListener(‘visibilitychange‘, onVisibilityChanged, false)

 

    推荐阅读