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

江枫思渺然 提交于 2019-12-10 19:00:54

问题


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?


回答1:


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
}



回答2:


Browsers handle domain security on the principle of Same Origin Policy

And the laws of cross domain communication

Also you will find an interesting read on the creationg of read-write JS APIs on this blog post http://piecesofrakesh.blogspot.com/2007/11/how-to-build-readwrite-javascript-api.html



来源:https://stackoverflow.com/questions/513800/is-there-a-way-to-access-an-iframes-window-object-from-the-canvas-in-fbjs-fac

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!