Reputation:
my web-app has this:
$(window).bind('beforeunload', function() {
if(unSavedChanges == true)
{
return 'You have unsaved changes';
}
return null;
});
this works fine in Safari and Firefox (with the exception that firefox does not show my custom message in it's onBeforeUnload dialog). However on IE 8 on Windows 7, it always shows the onBeforeUnload notification, specifically if there are no unsaved changes, it would just say "null". How can I prevent IE from showing onBeforeUnload notification when user has saved everything and wants to navigate away?
as per Jon's suggestion, I have removed the return null
line, the code now reads
$(window).bind('beforeunload', function() {
if(unSavedChanges == true)
{
return 'You have unsaved changes';
}
});
Upvotes: 15
Views: 10467
Reputation: 27394
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';
}
Upvotes: 0