Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Iframe ContentWindow

When I try to get the contentwindow out of an iframe, using

var contentWindow = document.getElementbyId('iframe').contentWindow 

sometimes it returns "Window undefined" because the contentWindow doesn't exist. I can't seem to run a check for it using

if (contentWindow === unidentified) or if (contentWindow === null)

as it just errors out of the code if I try to grab values out of it. Has anyone else run into this problem and figured out a solution?

like image 972
TimelierSword Avatar asked Jan 22 '11 02:01

TimelierSword


2 Answers

Are you typing it properly? getElementByID not getElementbyId. Did you confirm that that returns an element before querying contentWindow? Are you querying it after it loads?

Are you doing gEBI after DOM ready or page load? Did you throw in alerts on the element? Is the domain in the iframe the same as the origin domain? What browser are you using?

if (contentWindow === unidentified) or if (contentWindow === null)

There is no such thing as unidentified it's undefined. Slow down and be accurate.

like image 77
meder omuraliev Avatar answered Oct 31 '22 19:10

meder omuraliev


Try this

var iframeElem = parent.document.getElementById("iframe");
var win = iframeElem.contentWindow;
like image 20
Wazy Avatar answered Oct 31 '22 20:10

Wazy