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!