Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android won't open google play links from javascript in web-app

I've got an html app which is wrapped in Phonegap and in the android store.

I'd like to put a link to the app within the app for users to update if an update is available.

According to the documentation, and some results here on SO, on devices,

< a href="market://details?id=com.myapp.name" > Update App </a>

opens the store, but I need to open the link from javascript.

I've tried both window.open and window.location.href but both of those open the browser and I get a URL not found error. The url in the browser turns out to be http://market://details...

Anybody know why or how I can link directly to the store, not to the play website?

---------------UPDATE -------------------

I don't want to open the play store in a browser, I am trying to open the native play store.

I know this is possible because smartbanner opens the proper store. http://jasny.github.io/jquery.smartbanner/

But I can't get it to work.

like image 855
pedalpete Avatar asked Dec 26 '22 04:12

pedalpete


2 Answers

Turns out that phonegap basically steals the window.open, and was checking the protocol used within. Therefore using '_blank' within phonegap doesn't open a new browser window (as you'd expect) but instead opens a browser window within phonegap, which phonegap owns and only lets use either http or https protocols (I'm assuming those are the only two).

In order to pass a link to the system browser, you have to use

window.open("market://details?=com.your.app","_system");

and that will send the request out of phonegap and open the link in the native browser, which then redirects correctly to the native app store.

like image 99
pedalpete Avatar answered Dec 30 '22 07:12

pedalpete


User target="_top"

 <a href="market://details?id={package_name}" target="_top">App</a>
like image 23
Jokry Avatar answered Dec 30 '22 07:12

Jokry