views:

300

answers:

2

What options do I have preventing the user from just closing the browser or navigating to another site? (of course I can't prevent him pulling the plug on the computer, etc.: I just want to show him a warning)

+5  A: 

Hi,

you could use the JS beforeunload-event in order to achive this. Btw.: could you be a little more specific in your question?

cheers

       K
KB22
A: 

You should use the onunload event.

<script>
function onExitHandler() {
  // called when user about to leave the page
}
</script>
<body onunload="onExitHandler()">
...
</body>

You can see an example here: http://www.w3schools.com/jsref/jsref%5Fonunload.asp

Itay
The unload event is too late. You have to use beforeunload if you want to prevent the user leaving (which was the question).
jhurshman