標籤:android blog http io ar os sp java on
當使用者在用mobile browser瀏覽該網站的時候會點擊一個按鈕/超連結,通過這個按鈕的點擊事情需要開啟安裝在原生應用程式,或者如果本機沒有安裝該應用程式則開啟市集並開啟該程式在商店中的搜尋結果頁面。
下面是實施跳轉的HTML + javascript原始碼。
<html> <head> <meta name="viewport" content="width=device-width" /> </head> <body> <h2><a id="applink1" href="mtcmtc://profile/116201417">Open scheme(mtcmtc) defined in iPhone with parameters </a></h2> <h2><a id="applink2" href="unknown://nowhere">open unknown with fallback to appstore</a></h2> <p><i>Only works on iPhone!</i></p> <script type="text/javascript"> // To avoid the "protocol not supported" alert, fail must open another app. var appstore = "itms://itunes.apple.com/us/app/facebook/id284882215?mt=8&uo=6"; function applink(fail){ return function(){ var clickedAt = +new Date; // During tests on 3g/3gs this timeout fires immediately if less than 500ms. setTimeout(function(){ // To avoid failing on return to MobileSafari, ensure freshness! if (+new Date - clickedAt < 2000){ window.location = fail; } }, 500); }; } document.getElementById("applink1").onclick = applink(appstore); document.getElementById("applink2").onclick = applink(appstore); </script> </body> </html>
android可以參見這個哥們的部落格http://my.oschina.net/liucundong/blog/354029
android/iPhone:如何從browser直接開啟應用程式或者沒有應用程式開啟市集