javascript - 如何在 Facebook 应用内浏览器中接收邮件?

标签 javascript facebook webview

我正在尝试从打开的窗口将邮件发送到 Facebook 应用程序浏览器中的开启器,但“开启器窗口”从未收到消息。问题的原因可能是什么?

接收方:

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(/page/) 打开它,它似乎被特别阻止了: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 它,它只是说空。

关于javascript - 如何在 Facebook 应用内浏览器中接收邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57371428/

相关文章:

javascript - 即使从数据列表中选择选项也会触发响应式(Reactive)表单的 valueChanges 事件

javascript - iframe 中的 jQuery 延迟加载图像

objective-c - 使用 Facebook Scrumptious 应用示例代码

android - WebView 的 Firebase 性能监控

javascript - 在 flutter_inappwebview 的 iframe 中运行 JavaScript

javascript - 为什么浏览器会替换通过 css 分配的宽度值?

javascript - Jquery Sortable,在启用溢出的容器内使用链表

facebook - Facebook 应用程序是使用 PhoneGap 或 Appcelerator 等移动开发框架构建的吗?

javascript - FB.login 弹出窗口不居中,甚至位于与事件浏览器窗口不同的屏幕上

JavaFX webview 不保存 cookie