tags:

views:

16

answers:

1

I found it very useful.But how can they get it?

thank you very much!!

+1  A: 

You could use the window.onbeforeunload event:

window.onbeforeunload = function (e) {
    var e = e || window.event;

    // For IE and Firefox
    if (e) {
        e.returnValue = 'Are you sure you want to leave this page';
    }

    // For Safari
    return 'Are you sure you want to leave this page';
};

Obviously you shouldn't attach this event systematically because it is very annoying from a user standpoint. You should attach it only in case for example that the user has some unsaved work in order to warn him as StackOverflow does.

Darin Dimitrov

related questions