ionic 2 - Inappbrowser event fire after second call

牧云@^-^@ 提交于 2019-12-11 05:56:31

问题


I use inappbrowser plugin in ionic 2 application like this :

import {InAppBrowser} from 'ionic-native';

and use it like this :

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>

when click on launch button for first time and after close browser, exit event not fire but when for second time click on launch button and after close browser exit event is fire


回答1:


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

Try to put the calls to any InAppBrowser methods inside Plaform.ready(), like so:

...
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);
                    }
                );
            }
        );
    };
    ...
}


来源:https://stackoverflow.com/questions/44327252/ionic-2-inappbrowser-event-fire-after-second-call

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!