Using "window" and "document" in an iFrame
I'm developing an iFrame Facebook application. The iFrame has a swf. We need to get access to that swf through javascript.
This iFrame has a swf that needs to be put inside a Javascript variable so that we 开发者_如何学Ccan call ExternalInterface functions from.
Right now, our "flash" variable is undefined because we can't seem to access elements of that iFrame, as that evokes a sandbox security warning, as evoking window or document in this way means we're accessing this content from the parent's site, which is Facebook.
Right now, we're doing something like:
if(navigator.appName.indexOf("Microsoft") != -1)
{
flash = window["swfr"];
}
else
{
flash = document["swfr"];
}
I'm sure there's a way to make this work, but unfortunately, I'm just not seeing it. I appreciate any help.
Possibly Related ?
The child iframe page has a reference to the parent, not the other way around. So you should be able to give a back reference then use that to manipulate your flash object. This blog shows how to call a parent function (you pass the flash obj as a reference): http://www.velocityreviews.com/forums/t164727-a-challenge-call-parent-javascript-function-from-inside-an-iframe.html
parent page:
function ManipulateFlashObj(obj)
{
alert(obj);
}
child (iframe page):
parent.ManipulateFlashObj(document.getElementById("swf"));
If the parent page and the iframe page are on different DNS domains, the browser will not allow the parent to see into the child context nor the child to see the parent context. To move data between the parent and child, you'll need to use cross-domain scripting techniques (XSS) such as passing data on the iframe URL.
It should work if the script is within the IFrame, since the IFrame will have the same domain as the SWF file. If, however, the iframe is served from some facebook URL, you'll have to create/update the cross-domain.xml file on the host which serves the SWF.
Also, try swfObject, as it has a much wider browser compatibility, and is even used by Flash Builder 4 in the auto generated html template.
http://code.google.com/p/swfobject/
精彩评论