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 v开发者_如何学Calues 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;
Try specifying what data you want from the object you call here
var contentWindow = document.getElementById('iframe')
by doing this
var contentWindow = document.getElementById('iframe').contentWindow
This worked for me
精彩评论