< P >< href= "xxx://app/question/95"> Click to jump, direct reply registration </a ></p>
1 /*Global Navigator, document, window*/2 3 varUA = {4App:navigator.userAgent.indexOf (' Naitangapp ') >= 0,5WeiXin:navigator.userAgent.indexOf (' Micromessenger ') >= 0,6Android:navigator.userAgent.indexOf (' Android ') >= 0,7IPhone:navigator.userAgent.indexOf (' iPhone ') >= 08 }9 varTimeoutTen functionreplaceschema (href) { One varschema = [ A[' xxx://app/question/', ' http://www.xxx.com/question/'] - ] - varLen =Schema.length the for(vari = 0; i < Len; i + = 1) { -href = Href.replace (schema[i][0], schema[i][1]) - } - returnhref + } -Document.queryselector (' body '). AddEventListener (' click '),function(e) { + varTG = (window.event)?E.srcelement:e.target A while(Tg.nodeName.toUpperCase ()!== ' BODY ') { at if(TG && tg.nodeName.toUpperCase () = = = ' A ') { - varhref = tg.getattribute (' href ') - if(Href.indexof (' naitang://') = = = 0) { - E.preventdefault () - if(UA. APP) { -Window.location.href =href in}Else if(UA. Weixin) { -window.location.href = ' http://a.app.qq.com/o/simple.jsp?pkgname=com.xxxxxx ' to}Else if(UA. Android) { +Window.location.href =href -Timeout = SetTimeout (function() { thewindow.location.href = ' http://a.app.qq.com/o/simple.jsp?pkgname=com.xxxxxx ' *}, 1000) $}Else if(ua.iphone) {Panax NotoginsengWindow.location.href =href -Timeout = SetTimeout (function() { thewindow.location.href = ' itms-apps://itunes.apple.com/cn/app/nai-tang/id00000000?mt=8 ' +}, 1000) A}Else { the varPchref = Tg.getattribute (' data-pc ')) +href = pchref?pchref:replaceschema (HREF) -Window.location.href =href $ } $ } - Break -}Else { theTG =Tg.parentnode - }Wuyi } the},false) - functiononvisibilitychanged () { Wu varHidden = Document.hidden | |Document.webkithidden - if(Hidden &&Timeout) { About window.cleartimeout (Timeout) $ } - } -Document.addeventlistener (' Visibilitychange ', onvisibilitychanged,false)
HTML5 evoke APP