Saturday, April 9, 2016

Inject css into frame

I have an original html like below:

<html>
  <head/>
  <frameset>
    <frame>
      <html>
        <head>
       
        </head>
        <body>
        </body>
     </frame>
     <frame>
      <html>
        <head>
       
        </head>
        <body>
        </body>
     </frame>
     <frame>
      <html>
        <head>
       
        </head>
        <body>
        </body>
     </frame>
</frameset>
</html>

I must use GWT for this original html. I can use GWT.create() and CssResource.ensureInjected() to inject css into top <head>. Because the injected css is not available for frame, I have to inject these css into frame. I don't know why the following code doesn't work:

ClientBundle globalClientBundle = GWT.create(GlobalClientBundle.class);
globalClientBundle.css().ensureInjected();
NodeList<Element> frameNodeList = document.getElementsByTagName("frame");
int length = frameNodeList.getLength();
logger.info("frame size=" + length);
for (int i=0; i<length; i++) {
FrameElement frameElement = (FrameElement)frameNodeList.getItem(i);
logger.info("Frame(id=" + frameElement.getId() + ", name=" + frameElement.getName() + ")");
Document ownerDocument = frameElement.getOwnerDocument();
HeadElement head = ownerDocument.getHead();
if (head != null) {
StyleElement styleElement = ownerDocument.createStyleElement();
HeadElement.as(head).appendChild(styleElement);
String cssText = globalClientBundle.css().getText();
styleElement.setInnerHTML(cssText);

logger.info("Inject css into frame");
}
}

The above code is executing well. But I cannot see any <style> in html code.

Thanks,

David

--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment