标签: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直接打开应用程序或者没有应用程序打开应用商店
标签:android blog http io ar os sp java on
原文地址:http://my.oschina.net/liangxp/blog/354391