1. Set the link in HTML
<a id="open-app" href="[scheme]://[host]/[path]?[query]">打开应用</a>
Href= "[Scheme]://[host]/[path]? [Query] "
Scheme can be set up in the app itself as arbitrary, the Android and iOS are set to the same
2, if the local application exists, directly open the app; if it doesn't exist, time to jump to AppStore
You need to determine whether the browser is in iOS or Android
varOpenapp = function () { varBtnopenapp = document.getElementById ("Open-app"); Btnopenapp.onclick = function () { //Open local application function varopen= function(URL){ varTimeout function try_to_open_app() {Timeout = SetTimeout ( function(){window.location.href="url"; Console.log ("a") },Ten); } Try_to_open_app (); }if(/android/i. Test (Navigator.useragent)) {//alert ("This is Android ' browser."); /This is the Android platform under the browser if(/micromessenger/i. Test (Navigator.useragent)) {alert ("This is Micromessenger browser, please open it using your local browser");//This is the platform under the browser}Else{Open (Andorid app market URL); } }if(/(Iphone|ipad|ipod|ios)/ I. Test (Navigator.useragent)) {//alert ("This is IOS ' browser."); /This is the iOS platform under the browser if(/micromessenger/i. Test (Navigator.useragent)) {alert ("The built-in browser does not support opening the local app, please click on the upper right corner to open with local browser");//This is the platform under the browser}Else{Open (iOS app market URL); } } };}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HTML5 write links to open iOS and Android native apps