【发布时间】:2019-07-07 07:09:21
【问题描述】:
我正在为我的 ionic 应用程序使用 cordova inappbrowser。我需要检测 url 何时重定向到 http://xx.success.html
or
http://xx.failure.html
我的代码:
public openWithCordovaBrowser(url: string) {
//where are events triggered (_self,_blank,_window)?
let target = "_self";
let inAppBrowserObject = this.inAppBrowser.create(url, target, this.inAppBrowserOptions);
//When the page is success, close inappbrowser
if (inAppBrowserObject.on('loadstart').subscribe) {
inAppBrowserObject.on('loadstart').subscribe((e: InAppBrowserEvent) => {
if (e && e.url) {
if (e.url.includes('success.html')) {
inAppBrowserObject.close(); //not reached?
}
}
});
}
//When the InAppBrowser is closed, check and use the last viewed URL
if (inAppBrowserObject.on('exit').subscribe) {
inAppBrowserObject.on('exit').subscribe((e: InAppBrowserEvent) => {
if (url) {
console.log('exit: ' + e); //this is reached
}
});
}
}
不起作用,inAppBrowserObject.close() 永远不会被调用。
chrome 开发控制台中的错误:
Error in Success callbackId: InAppBrowser780208391 : TypeError: Object(...) is not a function
cordova.js:310 TypeError: Object(...) is not a function
at InAppBrowserObject.close (vendor.js:81063)
at SafeSubscriber._next (main.js:411)
at SafeSubscriber.__tryOrUnsub (vendor.js:20899)
at SafeSubscriber.next (vendor.js:20846)
at Subscriber._next (vendor.js:20786)
at Subscriber.next (vendor.js:20750)
at Channel.fire (cordova.js:843)
at InAppBrowser._eventHandler (inappbrowser.js:48)
at cb (inappbrowser.js:108)
at Object.callbackFromNative (cordova.js:291)
但是关闭浏览器调用console.log('exit: ' + e);
【问题讨论】:
-
你能发布 nAppBrowserObject.on('loadstart') 的输出吗?
-
添加了调试输出
标签: cordova ionic-framework phonegap-plugins hybrid-mobile-app