my web-app has this:
$(window).bind(\'beforeunload\', function() {
if(unSavedChanges == true)
{
return \'You have unsaved changes\';
}
I use normal javascript for this and works fine
function setConfirmUnload(on) {
window.onbeforeunload = (on) ? unloadMessage : null;
}
function unloadMessage() {
return 'Please stay on the page';
}
Remove the return null
line and it should be fine (in Javascript null
and undefined
are different things).
By the way, MDN says that for maximum compatibility you should be accepting an event
parameter and setting event.returnValue
as well.