Opening two instances of InAppBrowser (_system and _blank) prevents events from triggering

久未见 提交于 2019-12-01 23:49:48

It seems that you need to initialize the IAB each time you do a new window.open() if you don't do that the event listeners don't work.

If I use that code it works like a charm.

window.openIAB = function(url, target, options) {

    var self = this;
    var ref = window.open(url, target, options);

    var handleChildEvents = function(ev) {

        if (ref != undefined) {

            // Closing the iab window 
            if (ev.url.match('#close')) {
                ref.close();
                ref = undefined;
            }

            // Opening card url with system browser
            if (ev.url.match('#openccard')) {
                var customerId = ev.url.split('#openccard-')[1];
                self.ref2 = self.openIAB(
                    'https://www.test.com?customerID=' + customerId,
                    '_system', 
                    'location=yes'
                );
            }

        } else {
            console.log('InAppBrowser has no reference');
        }

    };

    ref.addEventListener('loadstart', handleChildEvents);
    ref.addEventListener('loadstop', handleChildEvents);

    ref.addEventListener('loaderror', function(ev) {
        console.log('error while loading page');
        ref.close();
        ref = undefined;
    });

    ref.addEventListener('exit', function(ev) {
        dialog.close();
    });

    return ref;
};
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!