我的是一个基于canvas的FB App。在 Chrome 和 Firefox 上都遇到问题(尽管通常是 Chrome):
1.当我在新的隐身 Chrome 窗口 ( https://apps.facebook.com/myfbappnamespace/ ) 上点击我批准的 fb 应用程序安全 URL 时,以下错误只是第一次出现,当我刷新页面时错误消失了(大部分次)
The page at about:blank displayed insecure content from http://static.ak.facebook.com/connect/xd_arbiter.php?version=18#cb=f2e4fe7b…os.com%2Ff4aeadb2&domain=www.mydomain.com&relation=parent&error=unknown_user.
Unsafe JavaScript attempt to access frame with URL http://www.mydomain.com/control/myfacebookapp/ from frame with URL http://static.ak.facebook.com/connect/xd_arbiter.php?version=18#cb=f2e4fe7b…os.com%2Ff4aeadb2&domain=www.mydomain.com&relation=parent&error=unknown_user. The frame requesting access set 'document.domain' to 'facebook.com', but the frame being accessed did not. Both must set 'document.domain' to the same value to allow access.
xd_arbiter.php:18Unsafe JavaScript attempt to access frame with URL http://www.mydomain.com/control/myfacebookapp/ from frame with URL http://static.ak.facebook.com/connect/xd_arbiter.php?version=18#cb=f2e4fe7b…os.com%2Ff4aeadb2&domain=www.mydomain.com&relation=parent&error=unknown_user. The frame requesting access set 'document.domain' to 'facebook.com', but the frame being accessed did not. Both must set 'document.domain' to the same value to allow access. xd_arbiter.php:18
2.当我尝试 http url( http://apps.facebook.com/myfbappnamespace/ ) 时,控制台中显示的错误是:
Unsafe JavaScript attempt to access frame with URL http://apps.facebook.com/myfbappnamespace/ from frame with URL https://s-static.ak.facebook.com/connect/xd_arbiter.php?version=18#channel=…Fcontrol%2Ffacebookappchannelurl%3Ffb_xd_fragment%23xd_sig%3Df23e84e85c%26. The frame requesting access has a protocol of 'https', the frame being accessed has a protocol of 'http'. Protocols must match.
现在,当我登录到我的 fb 帐户以查看这些错误发生了什么时,它们消失了,只是偶尔出现。我知道我在查询中使用的是“大部分时间”和“有时”,但这正是我正在发生的事情。我还搜索了论坛,发现 fb 已经解决了这个应该是 chrome 特定的老问题。我已确保我的 FB.init 和其他调用是特定于 location.protocol 值的。还在 Canvas url (http) 和安全 Canvas url (https) 中配置了正确的值。还尝试了两种设置: 帐户设置 -> 安全 -> 安全浏览 ->(启用和禁用)
如果我在某处遗漏了什么,有人可以帮忙吗?
最佳答案
有很多可能的问题。尝试使用以下解决方案之一:
- 协议(protocol)必须相同(因此尝试访问 iframe 的页面必须与提供 iframe 的站点具有相同的协议(protocol)),因此如果您在沙盒模式(http 而不是 https)下测试您的应用程序,请禁用您测试帐户的“安全浏览”模式
FB.init()
上的 channelUrl (参见下面的代码)- 启用apache 的headers mod 并将以下行放入您的.htaccess
- 将
<div id="fb-root"></div>
放在 body 标签之后,如 fb 文档中所述:https://developers.facebook.com/docs/reference/javascript/ - 尝试在用户操作(如点击登录按钮)后放置所有自动登录代码
- 像
http://yoursite.com?
一样从 Canvas URL(在应用程序→设置中)中删除尾部斜线 - 像这样编辑您的
<html>
标签:<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="https://www.facebook.com/2008/fbml">
.htaccess 的代码
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>
channel 问题的代码:
FB.init({
appId: '1234567890',
status: true,
cookie: true,
xfbml: true,
channelUrl : '//yoursite.com/channel.html'
});
您的服务器传送的 channel.html 应该包含这一行:
<script src="//connect.facebook.net/en_US/all.js"></script>
编辑
关于您的第一期:
The page at about:blank displayed insecure content from http://static.ak.facebook.com/connect/xd_arbiter.php?version=18#cb=f2e4fe7b…os.com%2Ff4aeadb2&domain=www.mydomain.com&relation=parent&error=unknown_user.
这是一个预期的异常,用于测试条件 - 它没有副作用,所以不要关心它。
请引用这个问题:Unsafe JavaScript attempt to access frame with URL: Domains, protocols and ports must match.
关于javascript - Facebook:不安全的 JavaScript 问题(document.domain 值应该相同),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14892556/