代码之家  ›  专栏  ›  技术社区  ›  Ole Haugset

重定向后弹出窗口上的Javascript eventlistener

  •  0
  • Ole Haugset  · 技术社区  · 6 年前

    我有以下代码,它创建了一个弹出窗口,并将eventlisteners添加到来自该窗口的消息中:

    let popupWindow = parent.window.open('/popup/' + encodeURIComponent(url), "popupwindow", "width=800, height=1000");
    if (popupWindow.addEventListener) {
      popupWindow.addEventListener('message', (result) => {
        console.log(result);
        if(result.data.success){
          this.orderCreated.emit(data);
          this.ShowOrderCreated();
          popupWindow.close();
        }
        if(result.data.success == false){
          popupWindow.close();
        }
      });
    }
    

    当我在进入该窗口时执行以下操作时,此操作有效:

    window.parent.postMessage({windowparent: true}, '*');
    

    然后由初始窗口的控制台接收。 window.location.href

    有没有办法绕过这个问题?

    0 回复  |  直到 6 年前