標籤:listen add tun target hang 報名 tno click ref
<p><a href="xxx://app/question/95">點擊跳轉,直接回帖報名</a></p>
1 /* global navigator, document, window */ 2 3 var UA = { 4 App: navigator.userAgent.indexOf(‘naitangApp‘) >= 0, 5 WeiXin: navigator.userAgent.indexOf(‘MicroMessenger‘) >= 0, 6 Android: navigator.userAgent.indexOf(‘Android‘) >= 0, 7 iPhone: navigator.userAgent.indexOf(‘iPhone‘) >= 0 8 } 9 var timeout10 function replaceSchema(href) {11 var schema = [12 [‘xxx://app/question/‘, ‘http://www.xxx.com/question/‘]13 ]14 var len = schema.length15 for (var i = 0; i < len; i += 1) {16 href = href.replace(schema[i][0], schema[i][1])17 }18 return href19 }20 document.querySelector(‘body‘).addEventListener(‘click‘, function(e) {21 var tg = (window.event) ? e.srcElement : e.target22 while (tg.nodeName.toUpperCase() !== ‘BODY‘) {23 if (tg && tg.nodeName.toUpperCase() === ‘A‘) {24 var href = tg.getAttribute(‘href‘)25 if (href.indexOf(‘naitang://‘) === 0) {26 e.preventDefault()27 if (UA.App) {28 window.location.href = href29 } else if (UA.WeiXin) {30 window.location.href = ‘http://a.app.qq.com/o/simple.jsp?pkgname=com.xxxxxx‘31 } else if (UA.Android) {32 window.location.href = href33 timeout = setTimeout(function() {34 window.location.href = ‘http://a.app.qq.com/o/simple.jsp?pkgname=com.xxxxxx‘35 }, 1000)36 } else if (UA.iPhone) {37 window.location.href = href38 timeout = setTimeout(function() {39 window.location.href = ‘itms-apps://itunes.apple.com/cn/app/nai-tang/id00000000?mt=8‘40 }, 1000)41 } else {42 var pchref = tg.getAttribute(‘data-pc‘)43 href = pchref ? pchref : replaceSchema(href)44 window.location.href = href45 }46 }47 break48 } else {49 tg = tg.parentNode50 }51 }52 }, false)53 function onVisibilityChanged() {54 var hidden = document.hidden || document.webkitHidden55 if (hidden && timeout) {56 window.clearTimeout(timeout)57 }58 }59 document.addEventListener(‘visibilitychange‘, onVisibilityChanged, false)
HTML5 喚起 APP