views:

27

answers:

2

I already have a 'Close' button that calls some javascript function. However, if the user just clicks the 'X' to close, the function is never called.

Any way to call a function when 'X' is clicked, or hide the 'X'?

Thanks.

A: 

You need to look into the (non-standard) onbeforeunload event

spender
A: 

Use the "onbeforeunload" javascript event to catch when the user attempts to close the browser or navigate away.

<html> 
<head>
<title>< /title>
</head>

<body onbeforeunload="alert('Closing');">
</body> 
</html> 
Carter