毕竟我解决了它这样的,我在这条路上学到了很多关于JSNI :-)
public native void handlePrintEvent() /*-{
var theInstance = this;
(function() {
var beforePrint = function() {
console.log('Functionality to run before printing.');
[email protected]::preparePrint()();
};
var afterPrint = function() {
console.log('Functionality to run after printing');
};
if (window.matchMedia) {
var mediaQueryList = window.matchMedia('print');
mediaQueryList.addListener(function(mql) {
if (mql.matches) {
beforePrint();
} else {
afterPrint();
}
});
}
window.onbeforeprint = beforePrint;
window.onafterprint = afterPrint;
}());
}-*/;
非常重要的与变量theInstance的东西,否则将无法正常工作!
此功能应该在你的Widget(com.myproject.xyz)类的C'tor被调用来安装打印处理器
然后,你需要实现的功能preparePrint()来执行一些特定的打印逻辑(这实际上是我需要的)。
希望别人发现这个有用
可以使用JSNI http://www.gwtproject.org/doc/latest/DevGuideCodingBasicsJSNI.html – WLGfx
或JsInterop。那将是做这种事情的“新”方式 –