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';
};