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

With this you can detect if you are in a browser:

if(window.hasOwnProperty('cordova')){ /* use webview */ }
else { /* use browser link */ }

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.


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 :)


Base on hhung, because core only detect if you are using a windows browser opening the application, but if you are using chrome mobile emulation, core will return false, but mobileweb will return true. Therefore you should use the following:

if(this.platform.is('core') || this.platform.is('mobileweb')) {
  this.isApp = false;
} else {
  this.isApp = true;
}