Onbeforeunload event parameter and empty return value

Q1: I have seen the following code in most sources:

window.onbeforeunload = function () {
    return 'You might lose your data!';
};

For example:

  1. beforeunload | onbeforeunload event (Internet Explorer)
  2. onbeforeunload event | beforeunload event JavaScript
  3. javascript - How can I override the OnBeforeUnload dialog and replace it with my own? - Stack Overflow

But on MDN the function has an extra parameter: FONT=Courier New[/FONT]. Why is that, what is the difference, and which is right?

Q2: It seems that any browser has a default confirmation message that you cannot customize. Chrome, for example, displays:

Are you sure you want to leave this page?

Can I content myself to this message and leave the return value empty:

return '';

“e” is often used as a variable indicating “event”.

The MDN page you linked to doesn’t show it being used, but the “More documentation is available there” links on that page do. i.e. https://developer.mozilla.org/en-US/docs/Web/Events/beforeunload

I was under the impression that onbeforeunload didn’t work in all browsers, and that it would eventually be dropped.

I know, as you see in my question title. The question is: why is it used here? It seems to be unnecessary.

It’s supported by the recent versions of all major browsers.
Not supported by iOS, though.

IE8 and earlier used a global event object to hold information about the current event. Other browsers including recent versions of IE pass the current event object as a parameter.

The current event object is often given the variable name “e” but you can call it whatever you like.

You don’t need to include it if you don’t need to reference the current event object.

You’d be unlikely to use it with a beforeUnload event as there you know what object triggered the event.

If you has a click event attached to the entire page then you could use the event object to determine which element in the page was clicked on and process differently depending on what was clicked without having to separately attach a click event to each element.