Problem description
If the app is installed locally then open directly, otherwise Apple will jump to App-store, Android will jump to the corresponding market
Solution One
HTML code in the a tag, for example, the default is to call Weixin scheme, go to open the local, if not then jump to the corresponding connection
<a href= "weixin://" class= "Btn-download" > Open now </a>
Bind event for Btn-download, if not resolved to protocol within 500MS, then jump to download link
varAppStore, UA =navigator.useragent; if(Ua.match (/android/i)) {AppStore= ' Market://search?q=com.singtel.travelbuddy.android '; } if(Ua.match (/iphone|ipod|ipad/) ) {AppStore= "Https://itunes.apple.com/cn/app/wei-xin/id414478124?mt=8&ign-mpt=uo%3D4"; } functionAppLink (fail) {return function(){ varClickedat = +NewDate; //During tests on 3G/3GS This timeout fires immediately if less than 500ms. SetTimeout (function(){ //to avoid failing in return to Mobilesafari, ensure freshness! if(+NewDate-clickedat < 2000) {window.location=fail; } }, 500); }; } $('. Icon-download,. Btn-download ') [0].onclick = AppLink (AppStore);
Solution II
By generating a hidden iframe,iframe in the page src points to the app protocol, such as the Weixin scheme, and listens to the OnError event, meaning that if the protocol cannot be resolved, the OnError event will be triggered, but I have tried it and failed. The code is as follows, please refer to.
Is there a div#iframe-box on the page to insert the generated IFRAME, or is it an example
varIFM = document.createelement (' iframe '), isInstalled; Ifm.style.display= ' None '; IFM.SRC= ' wixin://'; Ifm.onload=function(e) {varE = e | |window.event; E.preventdefault (); } ifm.onerror=function(){ //isInstalled = false;Alert (1); } document.getElementById (' Iframe-box '). appendchild (IFM);
However, the problem is that the IFRAME SRC successfully resolved to the protocol, it will jump directly, but can not parse the words, will not trigger the error event, this will continue to study
You can put the above code in a function, and then act as a response function for a button.
Solution Three
For iOS phones, you'll get the following wording
<meta name= "Apple-itunes-app" content= "app-id=414478124"/>
Put the above code in the head, according to name will also know the meaning, App-id is App-id, with the iOS phone to see the hint, andriod than can, the results of self-experiment. (iOS is powerful)
Follow-up study ...
How to use JS to detect whether the phone installs an app