fourOhFour
fourOhFour

Reputation: 77

How can I launch the inAppBrowser from my Ionic App? Nothing happens on DeviceReady

I'm following the steps listed on the https://github.com/apache/cordova-plugin-inappbrowser#reference guide to install and configure Cordova's inAppBrowser. It states to wrap it in a 'deviceready' event listener and to fire after that - but nothing is firing, not even my console.log.

document.addEventListener("deviceready", onDeviceReady, false)
  function onDeviceReady(){
   console.log('Called on device ready!')
   const browser = this.iab.create('https://google.com/', '_blank', 'location=no');
   browser.show();
   browser.on('loadstop').subscribe(event => {
    console.log('Loaded!')
    browser.close();
   });
  }

But nothing happens, and nothing is logged to the console.

What am I missing?

And yes, everything is installed and imported - went through those hurdles already.

Any advice or inputs are welcome, thanks!

Upvotes: 1

Views: 261

Answers (1)

Sébastien
Sébastien

Reputation: 12139

I don't know wher you wrote:

document.addEventListener("deviceready", onDeviceReady, false)

so I can't tell why the event doesn't fire. However Ionic provides a ready() method which is where you would put that initialization code.

This is copied straight from the default Ionic template in app.component.ts

export class AppComponent {
  constructor(
    private platform: Platform,
    private splashScreen: SplashScreen,
    private statusBar: StatusBar
  ) {
    this.initializeApp();
  }

  initializeApp() {
    this.platform.ready().then(() => {
      this.statusBar.styleDefault();
      this.splashScreen.hide();
    });
  }
}

You should have this code in your project if you created it with ionic start.

Upvotes: 1

Related Questions