daniel.auener
daniel.auener

Reputation: 1294

Open google play details page for an app via javascript redirect from android browser

I want my website to redirect to a specific app in the Google Play Market if it is opened on an android device. I followed the instructions on http://developer.android.com/guide/publishing/publishing.html:

"Display the details screen for a specific application: http://play.google.com/store/apps/details?id=<package_name>".

Works great with a link the user is actively clicking on:

<a href="http://play.google.com/store/apps/details?id=<package_name>">Download app</a>

But if I am detecting the device with javascript and trying to redirect the browser automatically changes the http://... to https://... and the user is redirected to the Google Play website instead of the Google Play app on the phone.

if(navigator.userAgent.toLowerCase().indexOf("android") > -1) {
    if(confirm("Download app?")) {
        window.location.href= "http://play.google.com/store/apps/details?id=<package_name>";
    }
}

Is there any way to change this behavior, my test device is a Samsung Galaxy with android 2.3.3?

Upvotes: 10

Views: 23014

Answers (3)

Yossi Neiman
Yossi Neiman

Reputation: 825

If you want to redirect to Google Play app try doing it from the server.

Client side attempts will not work.

PHP example

    header("Location: market://details?id=com.your.app");

Upvotes: 5

Fixticks
Fixticks

Reputation: 41

If the accepted answer does not work or fails to open in Chrome with this error

ERROR: ERR_UNKNOWN_URL_SCHEME

Change the window.location.href to window.location like this

if(navigator.userAgent.toLowerCase().indexOf("android") > -1) {
 if(confirm("Download app?")) {
    window.location= "market://details?id=<packagename>";
 }
}

Upvotes: 1

TerryProbert
TerryProbert

Reputation: 1134

This seems to work. The redirect opens the Google Play app while using the default browser, but translates the link to https:// play.google... when using chrome

if(navigator.userAgent.toLowerCase().indexOf("android") > -1) {
    if(confirm("Download app?")) {
        window.location.href= "market://details?id=<packagename>";
    }
}

Upvotes: 17

Related Questions