Cordova Inappbrowser多个窗口问题

时间:2016-01-23 14:22:15

标签: javascript cordova inappbrowser

我遇到Cordova Inappbrowser(phonegap)的问题。 示例:

var bot1, bot2;    //windows

function createb1(){ //create window1
    bot1 = window.open(encodeURI("http://yandex.ru?b=1"), '_blank', 'hidden=yes');
    bot1.val = "bot1";
    bot1.addEventListener('loadstop', function(event) {  //add listener
        console.log("B1 loadstop " + event.url);
        $.get("js/embed.js", function(data){
           bot1.executeScript({code: data});
        });
    });
}

function createb2(){  //create window 2
        bot2 = window.open(encodeURI("http://yandex.ru?b=2"), '_blank', 'hidden=yes');
        bot2.val = "bot2";
        bot2.addEventListener('loadstop', function(event) {  //add listener
            console.log("B2 loadstop " + event.url);
            $.get("js/embed.js", function(data){
                bot2.executeScript({code: data});
            });
        });
};

function goB1(){  //go page window 1
        console.log(bot1);
        bot1.executeScript({code: "goPage('http://yandex.com.ua?b=1');"});
}

function goB2(){  // go page window 2
    console.log(bot2);
    bot2.executeScript({code: "goPage('http://yandex.com.ua?b=2');"});
}

embed.js

function goPage(page){
    window.location.href = page;
}

控制台:

> createb1();
  B1 loadstop http://www.yandex.ru/?b=1
> goB1();
  InAppBrowser {channels: Object, val: "bot1", _eventHandler: function, close: function, show: function…}
  *B1 loadstop http://www.yandex.ru/ua/?b=1*
> createb2();
  B2 loadstop http://www.yandex.ru/?b=2
> goB1();
  InAppBrowser {channels: Object, val: "bot1", _eventHandler: function, close: function, show: function…}
  **B2 loadstop http://www.yandex.ru/ua/?b=1** 

当我创建window2(bot2)时 - window1(bot1)丢失了处理程序。为什么会这样?如何在bot1处理程序而不是bot2中捕获事件?

0 个答案:

没有答案