2

Window closing handler is not working on my code under Chrome (I'm on it's last version, 26)

I have a class that listens to the Window.ClosingEvent. If the window is being closed while the user is uploading a file (close the window, the user types another url...) the application prompts the user "are you sure?".

GWT 2.5.0 and 2.5.1 IExplorer 10 ok Firefox 21 ok Opera doesn't support the event yet. Chrome 26 is not working.

Here's the GWT code:

public abstract class ActiveUploadTransitionController extends TransitionController implements ClosingHandler {

...

@Override
    public void onWindowClosing(Window.ClosingEvent event){
        if(showMessage()){
            if(folder != null && folder.hasActiveFileUploads()){
                event.setMessage(getUploadActiveLeavingMessage());
            }
        }
    }

...
protected ActiveUploadTransitionController()
    {
...
Window.addWindowClosingHandler(this);
...
}
}

The above code complies and works properly in Explorer, Firefox so I think the code is ok.

The funny thing is that if I implement an isolated test in JavaScript it works fine in Explorer, Firefox and Chrome browsers.

//JavaScript

var handler = function(e){
        var show = true;
        if(show){
            var msg = "messageTest";
            (e || window.event).returnValue = msg;
            return msg;
        }
        return;
    }

    if(window.addEventListener){
        window.addEventListener("beforeunload", handler);
    }

Because the isolated JavaScript works I also tryed to implement it in native way. The same problem. Works in IExplorer, FireFox but not in Chrome.

var handler = function (e) {
    var showMessage = that.@com.skydox.client.home.ActiveUploadTransitionController::showMessage()();
    if(showMessage){
        var confirmationMessage = that.@com.skydox.client.home.ActiveUploadTransitionController::getUploadActiveLeavingMessage()();
        (e || window.event).returnValue = confirmationMessage;
        return confirmationMessage;
    }
    tmpBeforeUnload(e);
    return;
}
if($wnd.addEventListener){
     $wnd.onbeforeunload = handler;
}

This issue is getting me crazy. Any idea guys?

Thanks folks!

4

2 回答 2

0

我发现了同样的问题。非常令人沮丧。

该站点为大多数浏览器提供了很好的解决方法。

为 Chrome 提供的方法会抛出“你确定吗?” 用户关闭窗口的对话框。它需要这样做才能可靠地获取 onClose 事件。任何关闭处理都需要在此之前完成,因此如果用户单击“否”,页面/应用程序仍然需要运行。

于 2013-08-19T11:15:58.353 回答
0

我怀疑问题出在您的其他逻辑上,而不是onbeforeunloadChrome 的行为。为了验证这一点,硬编码你的 onbeforeunload 处理程序以返回一个字符串:

 $wnd.onbeforeunload = function() { return "Are you sure?" };

并确保实际调用了您的 JSNI 方法(在浏览器控制台中检查 window.onbeforeunload 以验证是否实际添加了处理程序)。

于 2013-08-19T14:10:45.160 回答