【问题标题】:GWT: add handler to native js event onafterprintGWT:将处理程序添加到本机 js 事件 onafterprint
【发布时间】:2020-06-10 05:11:44
【问题描述】:

我有一个代表文档打印预览的 GWT 小部件。 在此小部件中,打印按钮/操作由外部 Chrome 服务管理。 我需要从我的 java 代码中检测本机 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
}

【问题讨论】:

  • 您好,您能从这个弹出窗口中获取其他事件吗,例如“onload”和“onpageshow”?

标签: javascript java gwt event-handling


【解决方案1】:

实现这一点的一种方法是将 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"); 
}

【讨论】:

    猜你喜欢
    • 2012-01-05
    • 1970-01-01
    • 2021-02-26
    • 2018-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-07
    相关资源
    最近更新 更多