final IFrameElement iframe = Document.get().createIFrameElement();
FlowPanel innerBox = new FlowPanel() {
@Override
protected void onLoad() {
super.onLoad();
// Fill the IFrame with the content html
fillIframe(iframe, contentHtml);
// Add a HEAD element to the IFrame with the appropriate CSS
addHeadElement(iframe, cssUrl);
}
};
innerBox.getElement().appendChild(iframe);
and
private final native void fillIframe(IFrameElement iframe, String content) /*-{
var doc = iframe.document;
if(iframe.contentDocument)
doc = iframe.contentDocument; // For NS6
else if(iframe.contentWindow)
doc = iframe.contentWindow.document; // For IE5.5 and IE6
// Put the content in the iframe
doc.open();
doc.writeln(content);
doc.close();
}-*/;
I tried to get the head function on that page to work, but wasn't sure how to pass in the HTML and write it to the head element. Right now I'm just using <div style="background-color:red; font-size: 18px;">Hello World</div> to get the styles to work with the divs I need them to.
I end up with this in the dom:
<div><iframe><html><head></head><body><div style="position:fixed;top:0px;left:0px;color:red;background-color: blue; font-size:44px;">Hello World</div></body></html></iframe></div>
It works but I would imagine there's a better way.