Wednesday, October 5, 2011

Re: iframe with GWT

So I found this link http://bealetech.com/blogs/sean/2010/01/embedding-html-document-iframe-gwt and I got it to work using these functions: 

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.

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/Umjuy8C7iPgJ.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment