简体   繁体   English

GWT:将处理程序添加到本机 js 事件 onafterprint

[英]GWT: add handler to native js event onafterprint

I have a GWT widget representing a document print preview.我有一个代表文档打印预览的 GWT 小部件。 In this widget the print button/action is managed by an external Chrome service.在此小部件中,打印按钮/操作由外部 Chrome 服务管理。 I need to detect the native window.onafterprint event from my jave code.我需要从我的 jave 代码中检测本机 window.onafterprint 事件。

How can I do that?我怎样才能做到这一点?

Providing code with no success:提供没有成功的代码:

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
}

One way to achieve this is to export a Java handler to Javascript, this way the Javascript event can call the Java handler:实现此目的的一种方法是将 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;));
    }-*/;
}

So you can do:所以你可以这样做:

popup.onafterprint = function (ev) {
  handleOnAfterPrint("mess 2"); 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM