本文介绍了离子2 - 第二次呼叫后发生Inappbrowser事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在离子2应用程序中使用inappbrowser插件,如下所示:

I use inappbrowser plugin in ionic 2 application like this :

import {InAppBrowser} from 'ionic-native';

并像这样使用:

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

和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

推荐答案

也许第一次点击启动按钮时,设备平台尚未就绪?

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

尝试将调用放入 Plaform.ready() InAppBrowser 方法>,像这样:

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

这篇关于离子2 - 第二次呼叫后发生Inappbrowser事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-18 15:11