如何在GWT中获取HTMLIFrameElement的Document对象



我有[object HTMLIFrameElement],我想获取它的文档。我宁愿不使用本机方法。这是我现在尝试的,但不起作用。

//This is iFrame container with iFrame
mainWidge = new MainWidgetViewImpl(base);
//This is HTMLIFrameElement
Element iframeElement = mainWidge.getElement().getFirstChildElement();
//I've tried this, but it gets null pointer exception
IFrameElement iframe = (IFrameElement)mainWidge.getElement().getFirstChildElement();
//Here is: "Cannot read property 'document' of null"
Document doc = iframe.getContentDocument();

这意味着iframe的contentWindownull,如果iframe没有附加到文档中,就会出现这种情况。

contentWindow IDL属性必须返回iframe元素的嵌套浏览上下文的WindowProxy对象(如果有的话),否则为null。

--来源:https://html.spec.whatwg.org/multipage/embedded-content.html#dom-iframe内容窗口

iframe元素插入到具有浏览上下文的文档中时,用户代理必须创建嵌套的浏览上下文,然后"第一次"处理iframe属性。

从文档中删除iframe元素时,用户代理必须丢弃嵌套的浏览上下文(如果有的话)。

--来源:https://html.spec.whatwg.org/multipage/embedded-content.html#the-iframe元素

相关内容

  • 没有找到相关文章

最新更新