AndroidとiPhoneで使えるURLスキーム起動&アプリ未ダウンロードならストアへリダイレクトするJavaScriptサンプルコード
- 2013 7/22
Android と iPhone で使える URL スキーム起動&アプリ未ダウンロードならストアへリダイレクトするJavaScriptサンプルコードをご紹介します。
<!DOCTYPE html> <html lang="ja"> <head> <meta charset="utf-8"> <title>URL scheme / Redirect Test</title> <script type="text/javascript"> var userAgent = navigator.userAgent.toLowerCase(); window.onload = function(){ if (userAgent.indexOf("android") > -1) { // Launch myapp via URL scheme launch_frame.location.href= "myapp://"; setTimeout(function(){ // Open App DL page in Google Play location.href= "http://market.android.com/details?id=com.example.myapp"; } , 500); } else if (userAgent.search(/iphone|ipad|ipod/) > -1) { // Launch myapp via URL scheme launch_frame.location.href= "myapp://"; setTimeout(function(){ // Open App DL page in iTunes Store location.href= "itmss://itunes.apple.com/us/app/myapp/id123456789?ls=1&mt=8"; } , 500); } } </script> </head> <body> <div style="width:0; height:0; overflow:hidden;"> <iframe id="launch_frame" name="launch_frame"> </iframe> </div> </body> </html> |