我在Ionic 2应用程序中使用InAppBrowser插件:
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>
首次单击launch button
并在关闭浏览器之后,exit event
不是射击,但是第二次单击启动按钮,然后关闭浏览器exit event
是fire
也许您第一次单击启动按钮,设备平台尚未准备就绪?
尝试将调用拨打到Plaform.ready()
内的任何InAppBrowser
方法,例如:
...
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);
}
);
}
);
};
...
}