Javascript Iframe内容窗口

Javascript Iframe内容窗口,javascript,html,iframe,web,Javascript,Html,Iframe,Web,当我尝试从iframe中获取contentwindow时,使用 var contentWindow = document.getElementbyId('iframe').contentWindow 有时它返回“windowundefined”,因为contentWindow不存在。我似乎无法用计算机对它进行检查 if (contentWindow === unidentified) or if (contentWindow === null) 因为如果我试图从代码中获取值,它只会从代码中

当我尝试从iframe中获取contentwindow时,使用

var contentWindow = document.getElementbyId('iframe').contentWindow 
有时它返回“windowundefined”,因为contentWindow不存在。我似乎无法用计算机对它进行检查

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

因为如果我试图从代码中获取值,它只会从代码中出错。还有其他人遇到这个问题并找到了解决方案吗?

您键入的正确吗
getElementByID
getElementByID
。在查询
contentWindow
之前,您确认它返回了一个元素吗?您是否在加载后查询它

在DOM就绪或页面加载之后,您正在执行
gEBI
?你在元素上添加了警报了吗?iframe中的域是否与源域相同?你用的是什么浏览器

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

没有
未识别的
这是
未定义的
。放慢速度,保持准确。

试试这个

var iframeElem = parent.document.getElementById("iframe");
var win = iframeElem.contentWindow;

尝试从此处调用的对象中指定所需的数据

var contentWindow = document.getElementById('iframe')
通过这样做

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

这对我很有效

身份不明
让我笑了:)我们曾经都是初学者。