【发布时间】:2016-10-05 19:00:40
【问题描述】:
我们目前正在开发一款带有 cordova 和 InAppBrowser 插件的应用。我们正在尝试同时生成两个不同的 IAB 实例。一个带有 _system 浏览器,另一个带有 _blank 选项。
我们遇到的问题是,一旦我们打开 _system 浏览器的实例,我们似乎失去了对前一个浏览器的引用。因此,_system 浏览器关闭后,_blank IAB 上不会触发 close 事件。
这是实际代码的样子。
// Opening iab main window
var ref = window.open(global.chat_mediador, '_blank','location=no,toolbar=yes');
var handleEvents = function(event) {
// Closing the iab window
if (event.url.match('#close')) {
ref.close();
}
// Trigger custom event
if (event.url.match('#openccard')) {
window.open('https://www.test.example.url.com?customerID=' + event.customerId, '_system', 'location=yes');
}
}
// InAppBrowser events
// This events are duplicated because loadstop works on android and
// loadstart works on ios.
ref.addEventListener('loadstart', handleEvents, false);
ref.addEventListener('loadstop', handleEvents, false);
// Removing the dialog when we close the chat
ref.addEventListener('exit', function(event) {
generali.dialog.close();
}, false);
如您所见,我们使用 _blank 选项打开应用程序中的第一个 url。然后,如果在子应用程序中按下按钮,我们希望在 _system 浏览器中打开一个浏览器实例。
我们尝试过(没有运气):
为 _system 浏览器提供单独的参考。
window.open(global.url_ficha + customerId, '_system','location=no');
var cardsRef = window.open(
'https://www.test.example.url.com?customerID=' + customerId,
'_system',
'location=yes'
);
触发 _blank 浏览器引用之外的自定义事件
if (event.url.match('openccard')) {
var customerId = event.url.split('openccard-')[1];
var evt = document.createEvent("Event");
evt.initEvent("openccard",true,true);
evt.customerId = customerId;
document.dispatchEvent(evt);
}
有人知道发生了什么吗?
【问题讨论】:
标签: javascript cordova inappbrowser