日期:2014-05-17  浏览次数:20546 次

为 smartgwt 的HTMLPane指定IFrame的ID

这两天在支持项目时发现需要在smartgwt中调用HTMLPane中嵌入页面的javascript方法,那么就必须指定HTMLPane中IFrame的ID,但是HTMLPane类本身没有相关的方法。

google后发现有一种解决方案:

?1.使用

htmlPane.setContents( "<iframe id='" + "miMapa" + "' src='" + "map.html" + "' />" ); 
?

?2.在gwt中调用嵌入页面javascript方法可用:

?

public static native void calljs() /*-{          $wnd.document.getElementById("miMapa").contentWindow.alerta(); 
}-*/;

?这种方式有个缺点,就是在ie和火狐下iframe高度不是100%,他的解决方法是在主页面上加上下面的css:

<style type="text/css">
   html, body, div, iframe { margin:0; padding:0; height:100%; }
   iframe { display:block; width:100%; border:none; }
</style>

?

这个Css是否可行我还没验证,不过我找到了另外一个解决方法来指定IFrame的ID值,不需要添加CSS,效果和HTMLPane一样的。

?

方法是覆盖HTMLPane的getInnerHTML()方法,具体如下:

HTMLPane htmlPane = new HTMLPane(){
			@Override
			public String getInnerHTML() {
				String innerHTML = super.getInnerHTML();
				innerHTML = innerHTML.replaceFirst("<iframe ", "<iframe id='iframeID

' ");
				return innerHTML;
			}
			
		};