登录弹出窗口 - 向父

时间:2015-10-07 22:36:12

标签: javascript extjs spotify

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

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

但是在处理客户端登录后我遇到了问题 - 我放在父窗口上的任何监听器都不会从弹出窗口中选择事件或消息。

虽然如果用户已经登录,那么当窗口完成该过程时,侦听器可以正常工作

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

1 个答案:

答案 0 :(得分:0)

最后,我在父窗口上设置一个监听器,以监听来自子窗口的消息事件。

在父母身上:

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", "*");
相关问题