Possible Duplicate:
How to show the “Are you sure you want to navigate away from this page?” when changes committed?
Stackoverflow has a really interesting feature: if you start writing a new question, then you try to navigate away from the page, it will show an alert asking you confirm that you want to leave this page. This works whether you are typing a new address and entering it in the address bar, using the forward/back button, etc..
How does this work? I'd be interested to know less about the alert itself and more specifically about what event/code is triggering the alert.
Thanks!