以下是我目前正在使用的代码.我想了解如何监听inAppBrowser关闭事件?当一些人关闭inAppBrowser时,应用程序应显示某种警报消息. 根据documentation我必须使用browser.close(),但这不起作用. impo
根据documentation我必须使用browser.close(),但这不起作用.
import { Component } from '@angular/core'; import { NavController, NavParams, Platform, LoadingController } from 'ionic-angular'; import { InAppBrowser } from 'ionic-native'; @Component({ selector: 'page-payment-information', templateUrl: 'payment-information.html' }) export class PaymentInformationPage { constructor( public navCtrl: NavController, public navParams: NavParams, public platform: Platform, public loadingCtrl: LoadingController ) { this.platform = platform; } paymentForm(){ let browser = new InAppBrowser('https://www.stackoverflow.com', '_blank', 'hidden=no,location=no,clearsessioncache=yes,clearcache=yes&enableViewportScale=yes'); browser.close(); } }你的代码中有一些错误.
从documentation开始,browser.hide()没有做你想做的事情.
Hides an InAppBrowser window that is currently shown. Calling this has
no effect if the InAppBrowser was already hidden.
_blank用_system替换它,因为_blank在inAppBrowser中打开.你将无法听到近距离的事件.
现在,您可以订阅浏览器并收听它的事件,例如
//Events: loadstart, loadstop, loaderror, exit browser.on('exit').subscribe(() => { console.log('browser closed'); }, err => { console.error(err); });