Ionic 2 - Inappbrowser event fire after the second call

I am using the inappbrowser plugin in an ionic 2 application as follows:

import {InAppBrowser} from 'ionic-native';

and use it as follows:

launch(url){
      this.browser = new InAppBrowser( url, "_blank", "EnableViewPortScale=yes,closebuttoncaption=Done" );
      this.browser.on("exit")
          .subscribe(
              () => {
                this.close_event=true;
              },
              err => {
                console.log("InAppBrowser Loadstop Event Error: " + err);
              });
  }

and in html:

<button  ion-button icon-right color="danger"  (click)="launch('https://www.example.com')">launch
    <ion-icon name="refresh"></ion-icon>

the first time you press the button launch buttonand after closing the browser it exit eventdoes not start, but when the second time click the start button and after closing the browser it exit eventwill be turned on

+1
source share
1 answer

Perhaps the first time you click the Run button, the device platform is not ready yet?

Try putting calls into any methods InAppBrowserinside Plaform.ready(), for example:

...
import { Platform } from 'ionic-angular';
import { InAppBrowser } from '@ionic-native/in-app-browser';
...
export class HomePage {
    private iab: InAppBrowser;
    private platform: Platform;
    private browser;
    ...
    var launch = function(url) {
        this.platform.ready().then(
            () => {
                this.browser = this.iab.create( url, "_blank", "EnableViewPortScale=yes,closebuttoncaption=Done" );
                this.browser.on("exit").subscribe(
                    (event) => {
                        this.close_event = true;
                    },
                    (err) => {
                        console.log("InAppBrowser Loadstop Event Error: " + err);
                    }
                );
            }
        );
    };
    ...
}
0
source

Source: https://habr.com/ru/post/1678414/


All Articles