2014-11-07 42 views
0

我有[对象HTMLIFrameElement]我想要它的文档。我宁愿不使用本地方法。这是我现在尝试的,但它doies不工作。如何在GWT中获取HTMLIFrameElement的Document对象

//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(); 

回答

1

这将意味着iframe的contentWindownull,这将是如果IFRAME不附加到文件的情况。

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

- 来源:https://html.spec.whatwg.org/multipage/embedded-content.html#dom-iframe-contentwindow

iframe元件被插入具有浏览上下文,一个文档的用户代理必须创建嵌套浏览上下文,然后处理用于在iframe属性第一次”。

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

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

+0

我的目标是在显示之前注入到样式iframe的头部分。有没有办法做到这一点? – 2014-11-07 11:20:05

+1

将iframe附加到文档并不一定意味着使其可见。 – 2014-11-07 13:00:57

+0

这是某种解决方案。但我宁愿在onLoad事件之前注入这些样式。所以他们从一开始就是可用的。 – 2014-11-07 13:04:36