如何在 Facebook 应用内浏览器中接收邮件?
How to receive postmessage inside Facebook in-app browser?
我正在尝试从打开的 window 向 facebook 应用程序浏览器中的 opener 发送邮件,但 "opener window" 从未收到消息。问题的原因可能是什么?
接收方:
window.addEventListener('message', function (e) {
window.console.log("on message: " + e.data);
}, false)
发送方:
window.opener.postMessage('any Message', document.location.origin);
如果不查看您的更多代码就很难判断,但正如这个 Opening facebook connect window via javascript? 答案所述,如果您尝试访问 oAuth 页面,那是不可能的。
向我们展示您从何处获取变量 window.opener,这可能会增加一些上下文。
如果你从window.open(/页面/打开它,它似乎被特别阻止:How do I get around window.opener cross-domain security
如该问题所述:
NOTE
Social signups do not work for google, FB, etc within an iframe. I
believe they disallow them for security reasons.
也来自window.opener is null after redirect
window.opener is removed whenever you navigate to a different host
(for security reasons), there is no way around it. The only option
should be doing the payment in a frame if it is possible. The top
document needs to stay on the same host.
但是正如引用的第二个答案中提到的那样,不要在打开的页面上使用 window.opener,而是从原始页面开始执行所有操作,并且(如果您可以访问弹出窗口的源代码),制作一个另一页上的 onmessage,就像那里接受的答案中提到的那样,正确的方法只是相反:
Do it the other way around. Track the state of the child popup window
from the main (opener) window, and you could easily know when the
child window has been navigated back to you domain, so you could
"talk" to it again. But don't close the child window by itself. Let
the opener window obtain the result from the child window and then
close it.
参考:https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage#Example
例如,在您的起始页中,执行如下操作:
var popup = window.open(/*some URL*/);
popup.postMessage("hi");
addEventListener("message", function(e) {
console.log(e);
e.source.postMessage("Hi there"); //official workaround for window.opener on other page
})
然后在您的“/some URL/”源代码页中,执行如下操作:
addEventListener("message", function(e) {
console.log(e);
e.source.postMessage("hi back");
});
并尝试使用该策略,但 window.opener 似乎不可行。试试 console.logging 吧,它只是说 null。
我正在尝试从打开的 window 向 facebook 应用程序浏览器中的 opener 发送邮件,但 "opener window" 从未收到消息。问题的原因可能是什么?
接收方:
window.addEventListener('message', function (e) {
window.console.log("on message: " + e.data);
}, false)
发送方:
window.opener.postMessage('any Message', document.location.origin);
如果不查看您的更多代码就很难判断,但正如这个 Opening facebook connect window via javascript? 答案所述,如果您尝试访问 oAuth 页面,那是不可能的。
向我们展示您从何处获取变量 window.opener,这可能会增加一些上下文。
如果你从window.open(/页面/打开它,它似乎被特别阻止:How do I get around window.opener cross-domain security 如该问题所述:
NOTE
Social signups do not work for google, FB, etc within an iframe. I believe they disallow them for security reasons.
也来自window.opener is null after redirect
window.opener is removed whenever you navigate to a different host (for security reasons), there is no way around it. The only option should be doing the payment in a frame if it is possible. The top document needs to stay on the same host.
但是正如引用的第二个答案中提到的那样,不要在打开的页面上使用 window.opener,而是从原始页面开始执行所有操作,并且(如果您可以访问弹出窗口的源代码),制作一个另一页上的 onmessage,就像那里接受的答案中提到的那样,正确的方法只是相反:
Do it the other way around. Track the state of the child popup window from the main (opener) window, and you could easily know when the child window has been navigated back to you domain, so you could "talk" to it again. But don't close the child window by itself. Let the opener window obtain the result from the child window and then close it.
参考:https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage#Example
例如,在您的起始页中,执行如下操作:
var popup = window.open(/*some URL*/);
popup.postMessage("hi");
addEventListener("message", function(e) {
console.log(e);
e.source.postMessage("Hi there"); //official workaround for window.opener on other page
})
然后在您的“/some URL/”源代码页中,执行如下操作:
addEventListener("message", function(e) {
console.log(e);
e.source.postMessage("hi back");
});
并尝试使用该策略,但 window.opener 似乎不可行。试试 console.logging 吧,它只是说 null。