登录弹出窗口发送事件或消息给家长

Login popup window - issue sending event or message to parent

本文关键字:消息 事件 窗口 登录      更新时间:2023-09-26

我使用Extjs和Java。Spotify用户登录是在浏览器弹出窗口中进行的,我有所有的验证过程正常工作。

我需要告诉父窗口登录成功,然后关闭该窗口。

然而,在处理客户端登录后,我有一个问题-我放置在父窗口上的任何侦听器都不会从弹出窗口中拾取事件或消息。

如果用户已经登录,那么当窗口完成该过程时,侦听器将继续工作

关于Spotify重定向/登录过程破坏监听器/事件的任何线索将不胜感激。:)

最后,我在父窗口上设置了一个侦听器来侦听来自子窗口的消息事件,这是有效的。

在父节点上:

var width = 450,
height = 400,
left = (screen.width / 2) - (width / 2),
top = (screen.height / 2) - (height / 2);
var w = window.open('http://localhost:8080',
    'MyWindow',
    'menubar=no,location=no,resizable=no,scrollbars=no,status=no, width=' + width + ', height=' + height + ', top=' + top + ', left=' + left
);
 window.addEventListener("message", receiveMessage, false);
 function receiveMessage(event)
 {
     if (event.origin !== "http://localhost:8080") {
         return;
     }
     console.log('User logged in');
     window.removeEventListener("message", receiveMessage, false);
     w.close();
     // more logic...
  }

在子窗口上:

this.opener.postMessage("User logged in", "*");