PDA

View Full Version : iFrame use



omar.belkhodja
18 Nov 2011, 3:06 PM
Hello,

I have tried creating a new component that would integrated some html code into an iFrame. The iFrame is required to get rid of any CSS applied to the document. My code looks like


public class WelcomeMessageBox extends BoxComponent {

protected IFrameElement iFrame;
private String html = "";

public WelcomeMessageBox() {
}

protected void onRender(Element target, int index) {
Document d = Document.get();
setElement(DOM.createDiv(), target, index);

iFrame = d.createIFrameElement();
iFrame.setPropertyInt("frameBorder", 0);

el().dom.appendChild(iFrame);
iFrame.getContentDocument().getBody().setInnerHTML(html);
}

public void setHtml(String html) {
if(isRendered()) {
iFrame.getContentDocument().getBody().setInnerHTML(html);
}
else {
this.html = html;
}
}
}

The problem is that on IE I have a Null pointer access because when calling getBody within the onRender function, it returns Null. I don't know how to wait until the frame body is rendered.

Does anyone know how to perform that ?

Thanks !