![](/img/trans.png)
[英]How to add event to the body of a dynamically created iframe in jQuery?
[英]How to add a GWT module to a dynamically created Iframe
處理這種情況的最佳方法是什么?
詳細說明:
我有一個名為“ embed”的GWT模塊,該模塊生成embed.nocache.js文件。 我還有一個名為“ widget”的GWT模塊,該模塊生成widget.nocache.js文件。
我將embed.nocache.js添加到我的HTML頁面。 這會在HTML頁面中添加一個名為“小部件”的鏈接。 單擊此鏈接后,將打開一個iframe(例如,widget.html)。 widget.html包含一個指向widget.nocache.js的鏈接。 該文件將被下載,在iframe中執行並在iframe中放置一個水平面板。
現在,我需要消除widget.nocache.js文件的單獨下載。
假設我繼承嵌入的“ widget”模塊,則將其一起編譯並下載。 如何在動態創建的iframe中僅初始化與“小部件”相關的javascript?
創建自定義鏈接程序可以幫助嗎?
這樣的事情。 如果您的頁面上已經有一個IFrame,則只需將其加載到其中即可。 只要它不是跨站點頁面並且屬於您自己的域,該模塊就可以正常運行。
Document doc; // iframe document content
final String url_base = GWT.getHostPageBaseURL();
final Frame frame = new Frame(url_base + url_embedded); // your IFrame
frame.addLoadHandler(new LoadHandler() {
@Override
public void onLoad(LoadEvent event) {
doc = IFrameElement.as(frame.getElement()).getContentDocument();
wrapIFrameContent(); // If you need to wrap any widgets
}
});
frame.setStyleName("css_style_name");
RootPanel.get("content").add(frame);
基本上就是這樣。
您也可以嵌入多個頁面。
這只是Window.Location.assign(url)的替代方法
從IFrame頁面包裝小部件,如下所示:
Button add_module = Button.wrap(doc.getElementById("addmodule")); // button
Element delem = doc.getElementById(id_events_div); // DIV element
events_div = DivElement.as(delem);
events_list = ListBox.wrap(doc.getElementById(id_event_list)); // ListBox
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.