Cross-browser (FF4+ compatible) onbeforeunload
As of Firefox 4, and due to their bug 588292, onbeforeunload has been crippled to not help users give context to the question. This hack circumvents that with an extra fallback alert for FF4+ users.
HTML
<p>Click <a href="/" target="_self">unrelated nav</a> or the "Run" button to test this really useful functionality.</p>
<p>Firefox 4+ <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=588292">intentionally nukes</a> the helpful text message helping the user understand what makes it worth remaining on the page, thus forcing us to circumvent it by adding an extra alert.</p>
<p>Their reasoning seems crazy, context free, and is hurting user experience on well-behaved sites, in order to protect.</p>
JavaScript
var warning = 'You have unsaved edits.';
window.onbeforeunload = function warn() {
var hack = /irefox\/([4-9]|1\d+)/.test(navigator.userAgent);
if (hack) alert( warning + '\n\n(Pardon the double dialogs '
+ 'caused by Firefox bug 588292.)');
return warning;
};