String Name
String Name

Reputation: 202

Vuejs - Check if mobile application is installed or not

I'm working on a web application. Where I've placed a check to determine whether the link is opened on a mobile device or a laptop.

consider the link to be: my-site.com

Now my site also has a mobile application on android and ios. If the android app is installed and I click a button called "Start" it opens that link in the mobile app.

What I want to achieve:

What I want to achieve is if the android app is not installed and the "Start" button is clicked then it should open the playstore link for the app and if it is installed the button takes to the app.

Current Approach:

I've placed checks for device=mobile and where the device is android open the android app and where the device is ios open ios link but how to open playstore/app store if app is not installed.

Upvotes: 0

Views: 3623

Answers (1)

Burak Ayyildiz
Burak Ayyildiz

Reputation: 465

you can check the userAgent of the browser and add a link to the playstore. If the app is installed it will open the app if not the playstore of the native device will be opened.

add this functionality to the click event of the button:

...
         if(navigator.userAgent.toLowerCase().indexOf("android") > -1){
             window.location.href = 
           'http://play.google.com/store/apps/details?id=PACKAGEURL';
     }
         if(navigator.userAgent.toLowerCase().indexOf("iphone") > -1){
             window.location.href = 
       'http://itunes.apple.com/lb/app/PACKAGEURL';
     }

Upvotes: 2

Related Questions