[英]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.