[英]GWT: add handler to native js event onafterprint
我有一個代表文檔打印預覽的 GWT 小部件。 在此小部件中,打印按鈕/操作由外部 Chrome 服務管理。 我需要從我的 jave 代碼中檢測本機 window.onafterprint 事件。
我怎樣才能做到這一點?
提供沒有成功的代碼:
var popup = $wnd.open(url, title, ""); // this open the preview window
popup.onafterprint = function (ev) {
$wnd.console.log("mess 2"); // to try to see if detect the print button
}
實現此目的的一種方法是將 Java 處理程序導出到 Javascript,這樣 Javascript 事件就可以調用 Java 處理程序:
public MyUtilityClass {
public static int handleOnAfterPrint(String message) { ... }
public static native void exportStaticMethod() /*-{
$wnd.handleOnAfterPrint =
$entry(@mypackage.MyUtilityClass::handleOnAfterPrint(Ljava/lang/String;));
}-*/;
}
所以你可以這樣做:
popup.onafterprint = function (ev) {
handleOnAfterPrint("mess 2");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.