# On close window, call function

**URL:** https://forum.kirupa.com/t/on-close-window-call-function/297625
**Category:** Uncategorized
**Created:** [October 6, 2009, 5:27am UTC](https://forum.kirupa.com/t/on-close-window-call-function/297625 "2009-10-06T05:27:13Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![heiseman](https://avatars.discourse-cdn.com/v4/letter/h/85f322/32.png) [@heiseman](https://forum.kirupa.com/u/heiseman)
#### Post date: [October 6, 2009, 5:27am UTC](https://forum.kirupa.com/t/on-close-window-call-function/297625/1 "2009-10-06T05:27:13Z")

</div>

Hi, I’m trying to have a function called when the user closes a window. Here is the code I’m using at the moment:

\<body onUnload=fadeBack();\>  
‘fadeBack’ is the name of the function.

The problem is that onUnload also works when the page changes to another url. I only want it to work when the user actually closes the window. Is this possible? Is there an onUnload alternative which is specific to window closing?

Thanks.
