繁体   English   中英

在GWT中使用html + js库

[英]Use html + js libraries in GWT

我想包含一个使用js库的HTML页面。 我尝试运行的示例是json-editor项目中包含的demo.html。

这是我的html面板:

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

这是我的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(); 
}

结果:包含并显示了html,但未使用js库文件。

包含此js脚本的html页面的最简单方法是什么?

您将需要直接将HTML代码包含到GWT宿主页面中,而不是通过文本资源呈现它。

JS代码也可以直接包含在主页中,或者可以使用GWT提供的ScriptInjector

出于安全原因,我认为HTML小部件将忽略包含的JS代码。

您可以通过打开浏览器的“查看源代码”菜单项来验证这一点。

尝试使用com.google.gwt.user.client.ui.Frame类

Frame page = new Frame(path_to_html);

这会将iframe添加到您的页面中。

暂无
暂无

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

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