关闭由 Window.open() 在 Window class 中从 GWT 中的 JavaScriptObject 派生的选项卡

Close tab created by Window.open() in Window class derived from JavaScriptObject in GWT

我需要使用 GWT 关闭由从 JavaScriptObject 派生的 class 创建的 'tab'。 这是一个代码片段:-

public class MyWindow extends JavaScriptObject {
    // All types that extend JavaScriptObject must have a protected,
    // no-args constructor. 
    protected MyWindow() {}

    public static native MyWindow open(String url, String target, String options) /*-{
      return $wnd.open(url, target, options);
    }-*/;

    public static final native void close() /*-{
      this.close();
    }-*/;

    public static final native void setUrl(String url) /*-{
      if (this.location) {
        this.location = url;
      }
    }-*/;
}

public class MyUsingClass {
    // Have to have my own window object derived from JavaScriptObject.
    // Cannot use standard Window, because we are in an async callback,
    // and browser thinks it's a popup!
    MyWindow myWindow = MyWindow.open(null, "_blank", null);
    ...
    @Override
    public void registeredCallback(ArrayList<String> params)
    {
       ...
       // The URL passed to setUrl, is a call to a servlet that returns a 
       // response with Content-Disposition set in the header.
       // We get a File SaveAs Dialog box displayed, 'owned', I assume, by
       // this.myWindow.
       myWindow.setUrl(url);
       ...
    }

我遇到的问题是对话框按预期运行,并在按下“确定”或“取消”按钮时关闭,但是,我无法弄清楚如何[和where/when]关闭选项卡通过调用 MyWindow.open() 创建。 我猜我不知何故需要捕获由“文件另存为”对话框关闭触发的事件? 任何帮助将非常感激。 谢谢!

您不必打开新标签页 (window) 就可以看到保存文件对话框。我使用当前的 window 并且(当我确定文件可以访问时)我只是这样做:

Window.Location.assign(__file_servlet_path__);

在 servlet 中我设置了 Content-typeContent-disposition header:

resp.setHeader("Content-disposition", "attachment; filename=\"" + __file_name__ + "\"");