简体   繁体   中英

Use html + js libraries in GWT

I want to include a HTML page that uses js-libraries. The example I tried to get running is the demo.html contained in the json-editor project .

So this is my html panel:

HTML myHtmlPanel = new HTML();
myHtmlPanel.setHTML(MyHtmlResource.INSTANCE.getIntroHtml().getText());

And this is my html resource:

import com.google.gwt.core.client.GWT;
import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.TextResource;

public interface MyHtmlResource extends ClientBundle {
  public static final AnzeigeEinstellungTabWartungsplanEditorResource INSTANCE 
                      = GWT.create(AnzeigeEinstellungTabWartungsplanEditorResource.class);

   @Source("demo.html")
   public TextResource getIntroHtml(); 
}

Result: The html is included and displayed, but it doesn't use the js library files.

What is the most simple way to include this html page including the js scripts?

You will need to include the HTML code into the GWT host page directly instead of rendering it through text resources.

JS code can be included in the host page directly as well, or you can use ScriptInjector provided by GWT.

For security reason, I think HTML widget will ignore JS code included.

You can verify this by opening "View Source" menu item of your browser.

Try to use com.google.gwt.user.client.ui.Frame class

Frame page = new Frame(path_to_html);

this will add an iframe into your page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM