简体   繁体   English

在GWT中使用html + js库

[英]Use html + js libraries in GWT

I want to include a HTML page that uses js-libraries. 我想包含一个使用js库的HTML页面。 The example I tried to get running is the demo.html contained in the json-editor project . 我尝试运行的示例是json-editor项目中包含的demo.html。

So this is my html panel: 这是我的html面板:

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

And this is my html resource: 这是我的html资源:

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. 结果:包含并显示了html,但未使用js库文件。

What is the most simple way to include this html page including the js scripts? 包含此js脚本的html页面的最简单方法是什么?

You will need to include the HTML code into the GWT host page directly instead of rendering it through text resources. 您将需要直接将HTML代码包含到GWT宿主页面中,而不是通过文本资源呈现它。

JS code can be included in the host page directly as well, or you can use ScriptInjector provided by GWT. JS代码也可以直接包含在主页中,或者可以使用GWT提供的ScriptInjector

For security reason, I think HTML widget will ignore JS code included. 出于安全原因,我认为HTML小部件将忽略包含的JS代码。

You can verify this by opening "View Source" menu item of your browser. 您可以通过打开浏览器的“查看源代码”菜单项来验证这一点。

Try to use com.google.gwt.user.client.ui.Frame class 尝试使用com.google.gwt.user.client.ui.Frame类

Frame page = new Frame(path_to_html);

this will add an iframe into your page. 这会将iframe添加到您的页面中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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