6

How can I create a link button in my cordova app, which is redirecting to my app on iOS/Android/Amazon App Store depending on the device?

I have tried the following code, it gets in the iOS if clause, but it doesn't redirect me, neither gives an error:

if(window.cordova && window.device) {
    if (device.platform.toUpperCase() === 'IOS') {
        window.open("https://itunes.apple.com/gb/[OBFUSCATED]");
    } else if (device.platform.toUpperCase() === 'ANDROID') {
        window.open("https://play.google.com/store/apps/details?id=[OBFUSCATED]");
    } else {
        window.open("https://www.amazon.co.uk/[OBFUSCATED]");
    }
}
grg
  • 5,023
  • 3
  • 34
  • 50
user358448
  • 1,127
  • 3
  • 20
  • 39
  • Only next helped to me in 2020: https://stackoverflow.com/questions/45587421/ionic-how-to-open-play-store-application-detail-page-from-javascript/63905554#63905554 – Vladimir Tolstikov Sep 15 '20 at 15:52

2 Answers2

17

I figured it out:

IOS: itms-apps://itunes.apple.com/app/[appId]
Android: market://details?id=[appPackageId]
Amazon: amzn://apps/android?p=[appPackageId]
user358448
  • 1,127
  • 3
  • 20
  • 39
5

you can use Inappbrowser plugin.

Install inappbrowser plugin with following command:

cordova plugin add cordova-plugin-inappbrowser

and use following in your code:

  var isAndroid = navigator.userAgent.match(/android/i) ? true : false;
    var isIOS = navigator.userAgent.match(/(ipod|ipad|iphone)/i) ? true : false;

if(isIOS){
        window.open("https://itunes.apple.com/gb/app/[OBFUSCATED]","_system");
    } else if (isAndroid) {
        window.open("https://play.google.com/store/apps/details?id=[OBFUSCATED]", "_system");
    } else {
        window.open("https://www.amazon.co.uk/[OBFUSCATED]", "_system");
    }

Hope it will help you.

Ping comment if you stuck anywhere.

user358448
  • 1,127
  • 3
  • 20
  • 39
Naitik
  • 1,455
  • 15
  • 26