In IE and FF, i can attach an event handler to onBeforeUnload, and by passing a string to a property of the event, the user will see a dialog asking him whether he wants to
StackOverflow itself uses onbeforeunload, and it works fine for me in Safari:
onbeforeunload
function setConfirmUnload(a){window.onbeforeunload=a?function(){return a}:null}