Is there a way to access an iframe's window object from the canvas in FBJS? (facebook)

thesmart picture thesmart · Feb 5, 2009 · Viewed 11.4k times · Source

From the facebook canvas, I need to be able to access an iframe window. Normally you could do this with window.frames, but FJBS doesn't seem to allow access to the window object.

Has anyone figured out how to access window objects?

Answer

meouw picture meouw · Feb 5, 2009

you could try this. Let me know how it works.

var myIframe = document.getElementById('myIframeId');

// could retrieve window or document depending on the browser
// (if FBJS allows it!?)
var myIframeWin = myIframe.contentWindow || myIframe.contentDocument;

if( !myIframeWin.document ) { //we've found the document
    myIframeWin = myIframeWin.getParentNode(); //FBJS version of parentNode
}