我们正在构建一个从Facebook加载用户照片的应用。似乎facebook在多个主机上托管这些图像。发生安全沙箱违规后,是否可以动态添加跨域策略?
例如......
try
{
// Load the photo passed from the js method
}
catch (SecuritySandboxViolation Exception:e)
{
/*
Transform the exception message which contains the host url from...
"security error: Error #2048: Security sandbox violation: http://canvas-app.domain.com/SWF.swf cannot load data from security error: Error #2048: Security sandbox violation: http://facebook.tombstone.com/halloween-party-kit/GI_2011_09_TOMBSTONE_SPOOKIFY.swf cannot load data from https://s-hphotos-sjc1.fbcdn.net/229411_989116685126_5519474_47232933_4376850_n.jpg.22421_989116685126_5519474_47232933_4376850_n.jpg."
to...
https://s-hphotos-sjc1.fbcdn.net
*/
var host = e.getMessage();
// *magical string transformation*
Security.loadPolicyFile(host)
}
答案 0 :(得分:2)
如果facebook没有在他们的网站上放置跨域,则loadPolicyFile将无效。
但是,您使用什么来加载图像?通常,如果您只想显示图像,则不需要crossdomain.xml。
修改强>
https://s-hphotos-sjc1.fbcdn.net有一个允许的跨域,所以问题似乎在于如何加载图像。尝试为LoaderContext.checkPolicyFile = true
设置Loader
。
答案 1 :(得分:1)
更有可能的问题是,在您的SWF中嵌入或实际上是应用程序,您没有定义自己的跨域策略。您需要使用AS3代码明确执行此操作,或在您自己的域(托管SWF文件的域)上设置跨域策略。 Facebook加载它时可能会受到限制,因为你的SWF在你的策略文件中缺乏规范,或者它们一起缺失。记住事物的方向。您没有使用SWF加载Facebook,Facebook正在加载您的SWF。 (另请注意,Jacobs的回答也是正确的。)