HTML5 喚起 APP

來源:互聯網
上載者:User

標籤: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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.