Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

Every once in a while I click a link and see the following (I'm using FF 11.0):

enter image description here

I was wondering why FF does this on some redirects/links and not on others. I was thinking maybe it does that when you're on a page that contains a <form> element?

Thanks for any help here/

share|improve this question

1 Answer 1

up vote 2 down vote accepted

It's done with JavaScript, using the window.onbeforeunload event (Mozilla, IE).

Some browsers will even let you specify (part of) the text in the dialog box by returning a string from the event handler, but for security reasons, recent versions of Firefox (which you appear to be using) will ignore the string and just always present the same fixed message.

Here's some example code from the MDN page:

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

  // For IE and Firefox prior to version 4
  if (e) {
    e.returnValue = 'Any string';
  }

  // For Safari
  return 'Any string';
};
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.