1

I have a responsive WP blog that I converted into an application with cordova. (and added some extra features).

My idea would be to prompt an user that uses mobile to install the application if he run the site in his mobile browser instead in his application.

Something like:

if (isMobile() && !isApplication()) {
 var download = prompt('Would you like to install the application instead ?');
....
}

Maybe such a plugin does already exist in WP ?

yarek
  • 8,962
  • 25
  • 93
  • 180
  • You can use Javascript like : http://stackoverflow.com/questions/3514784/what-is-the-best-way-to-detect-a-mobile-device-in-jquery – Milap Jul 18 '16 at 14:01
  • the goal is not to detect if mobile. The goal is to detect isMobile && !isApplication() – yarek Jul 18 '16 at 14:02

1 Answers1

0

I use cordova-plugin-device to archive this for WP:

if(device.platform.toUpperCase().match(/WIN32NT|WINCE|WINDOWS/)) {
  var download = prompt('Would you like to install the application instead ?');
 ....
}
Frix33
  • 1,191
  • 11
  • 27
  • .match(/WIN32NT|WINCE|WINDOWS/)) ???? why do you detect windows plateform ? – yarek Jul 19 '16 at 09:46
  • This is for windows phone detection. To detect if is application simply check if device is defined. If plugin device does not exist you're running in mobile context but not in app. – Frix33 Jul 19 '16 at 09:51
  • do you think this can be done without any extra new plugin ? – yarek Jul 19 '16 at 09:56
  • If you don't need to check platform simply check if cordova exist (!!window.cordova) or raise a flag after cordova load as reported here: http://damien.antipa.at/blog/2014/02/08/3-ways-to-detect-that-your-application-is-running-in-cordova-slash-phonegap/ – Frix33 Jul 19 '16 at 09:58