gpt4 book ai didi

javascript - GWT:将处理程序添加到 native js 事件 onafterprint

转载 作者:行者123 更新时间:2023-12-01 18:13:48 27 4
gpt4 key购买 nike

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

关于javascript - GWT:将处理程序添加到 native js 事件 onafterprint,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60412058/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com