Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect if I am in browser (local development) in Ionic 2

I want to make sure to launch inappbrowser only if I am on devices (iOs, Android...), but if I am in browser (local development mode or just a Web App with gulp build), I want to just link to that page with target="_blank".

I am trying to reuse the Ionic 2 code as a Web App. So when I build the app, it will also work in browser desktop. So platform.ready() is not enough for me. As I need to know if user is on desktop browser and I can do something different.

like image 350
Hugh Hou Avatar asked Jul 19 '16 23:07

Hugh Hou


People also ask

How do I know if my mobile app is ionic?

To run your app, all you have to do is enable USB debugging and Developer Mode on your Android device, then run ionic cordova run android --device from the command line. Enabling USB debugging and Developer Mode can vary between devices, but is easy to look up with a Google search.


2 Answers

Here you go., you can use the following function in replacement of your click function.

onClickOfButton(){       // Check If Cordova/Mobile    if (this.platform.is('cordova')) {         window.location.href = url;    }else{         window.open(url,'_blank');    } } 

This can be helpful :)

like image 68
gsthina Avatar answered Sep 21 '22 07:09

gsthina


You can use platform.is('core'), true when on browser. Platform list:

  • android: on a device running Android.
  • cordova: on a device running Cordova.
  • core: on a desktop device.
  • ios: a device running iOS.
  • ipad: on an iPad device.
  • iphone: on an iPhone device.
  • mobile: on a mobile device.
  • mobileweb: in a browser on a mobile device.
  • phablet: on a phablet device.
  • tablet: on a tablet device.
  • windows: on a device running Windows.

See http://ionicframework.com/docs/v2/api/platform/Platform/ for more details.

like image 38
Hung Hoang Avatar answered Sep 20 '22 07:09

Hung Hoang