Firefox OnBeforeUnload Fun!

So Kevin correctly pointed out that you can do the same onbeforeunload behavior in Firefox as you can in Internet Explorer. It does require a little bit of a tweak to use the DOM event model, though:

window.onbeforeunload = function (oEvent) {
    oEvent.returnValue = "blah";

See, even JavaScript authors can learn something new every once in a while!


  1. José Jeria

    I think you wanna add:
    if(!oEvent) oEvent = window.event;

    to the above so it works in IE again ;-)

  2. José Jeria

    Sorry, I am blind, i though this was the same post as before, but updated...

Understanding JavaScript Promises E-book Cover

Demystify JavaScript promises with the e-book that explains not just concepts, but also real-world uses of promises.

Download the Free E-book!

The community edition of Understanding JavaScript Promises is a free download that arrives in minutes.