如何在GWT中打印一些元素 [英] How to print some elements in gwt
本文介绍了如何在GWT中打印一些元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在GWT中打印一页纸.
I want to print one panel of page in GWT.
但是有人说您必须使用 iframe
,因为它具有打印方法.
However someone said that you must use iframe
because it has print method.
我尝试了这段代码,但是它不起作用:
I tried this code but it does not work:
HTML html=new HTML("<iframe id="myframe"></iframe>") ;....
searchButton.setWidth("80px");
searchButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
MyNative.printIframeContent("myframe", "onlineMap");
}
});
map = new SimplePanel();
map.getElement().setId("onlineMap");
map.add(mapView.getMapWidget());
mapView
..是返回GWT MapWidget的类的实例,以这种方式,我想将GWT地图添加到iframe,然后使用iframe的打印功能来打印Google地图
mapView
.is an instance of a class that returns a GWT MapWidget and in this manner I want to add GWT map to iframe then use print capability of iframe to print google map
MyNative
是使用GWT JSNI调用printPage javascript函数的类
MyNative
is a class that use GWT JSNI to call the printPage javascript function
function printPage(idMap,idFrame) {
var myElement = document.getElementById(idMap);
var iframe = document.getElementById(idFrame);
var body = iframe.getElementsByTagName('body');
body.innerHTML = myElement;
iframe.contentWindow.print();
}
但浏览器无法加载iframe主体.
but browser can not load body of iframe.
推荐答案
您可以尝试以下操作:
String html = myPanel.getElement().getInnerHTML();
print(html);
public static final native void print(String html) /*-{
top.consoleRef=$wnd.open('','_blank', "");
top.consoleRef.document.write(html);
top.consoleRef.print();
top.consoleRef.document.close()
}-*/;
这篇关于如何在GWT中打印一些元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文