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?
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.
Try this
var iframeElem = parent.document.getElementById("iframe");
var win = iframeElem.contentWindow;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With