android/iPhone:如何從browser直接開啟應用程式或者沒有應用程式開啟市集

來源:互聯網
上載者:User

標籤: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直接開啟應用程式或者沒有應用程式開啟市集

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.