All overflow related websites ask "Are you sure you want to navigate away from this page" etc. etc. any time I try to leave a page after beginning a comment or answer - even if I have deleted ALL text in the input boxes after changing my mind. This is a small thing, but always bothers me. Should it be fixed?

  • I curious, and have noticed this previously, too - why is that items that get marked "status-completed" don't also get closed ?
    – warren
    Sep 26, 2009 at 8:15

2 Answers 2


It looks like SO attaches a listener for "beforeunload" event only after you start writing in a textarea. All that needs to be done here is check for a textarea value in that onbeforeunload event handler.

Right now:

window.onbeforeunload = function() {
  return 'You have started writing or editing a post.';

Could be easily changed to:

window.unbeforeunload = function() {
  // check other textareas too
  if ($('#wmd-input').val()) {
    return 'You have started writing or editing a post.';
  return false;
  • I don't think this is right. When you return "false". The message that is returned will contain the text "false". I tried this using "return null", which seems to work in FF and Chrome, but not in IE. In IE the text "null" is returned. :)
    – StefK
    Oct 17, 2011 at 8:51

It's a browser thing. For example opera does not do this. Since it doesn't fire onunload() properly.

So it would require a check of the data within whatever box was filled (which can by many, since there are comment boxes also). Which might be the reason for this.

Could/should it be fixed? Sure.
Is there time? No clue.

  • 3
    Opera is only different because it doesn't fire that event. It's not really a browser thing - all you'd have to do is add a check for the contents of the textarea. Which I would like.
    – Tom Ritter
    Sep 15, 2009 at 23:25
  • onunload() is a function fired by the browser. It's defined within the javascript handling of the browser. (Not StackOverflow). Hence it's a browser thing. Sep 16, 2009 at 9:11
  • 2
    I actually think it may be a browser thing. Since updating to Safari 4 i seem to be getting a lot more of those messages, so I think browsers may be adding this as a 'feature'.
    – Josh Hunt
    Sep 16, 2009 at 10:01
  • That's not a feature, that's a bug!
    – random
    Sep 16, 2009 at 12:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .