I wrote about a more-or-less reliable inference for detecting event support in modern browsers some time ago. You can see on a demo page that “beforeunload” is supported in at least Safari 4+, FF3.x+ and IE.
Edit: This technique is now used in jQuery, Prototype.js, Modernizr, and likely other scripts and libraries.