You cannot override the default implementation of beforeunload.
It is possible to connect an eventhandler to window.onbeforunload however, multiple handlers are a problem as the outcome may be different then what you expected.
The window.onbeforeunload
is a function, called by the native JS engine and it expects a String
. It will (allways) popup a native confirm(str)
dialog box, that is - if there is a str
returned from beforeunload function.
The only way to stop it from popping up the confirm
is to make a blocking call (like dijit.Dialog{..}).show(); while(1)
) and that is not really feasible, im sure you'd know that. Also, you would have to tell user, to also select 'no' in the dialog that will eventually pop when you break the endless while :)
So, example wise
var g_ChangesMade = false;
window.onbeforeunload = function() {
return (g_ChangesMade == true ? "Leaving Page with unsaved changes" : null);
}
would present a confirmdialog with the string - if global _ Changes Are Made
--------------------
| Leaving Page... |
| |
| Ok Cancel |
--------------------