开发者

calling a javascript function when user clicks 'X' to close a form

开发者 https://www.devze.com 2023-01-07 06:29 出处:网络
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.

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 wa开发者_如何转开发y to call a function when 'X' is clicked, or hide the 'X'?

Thanks.


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> 


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

0

精彩评论

暂无评论...
验证码 换一张
取 消