# Execute final code on window close

**URL:** <https://forum.kirupa.com/t/execute-final-code-on-window-close/70160>\
**Category:** Uncategorized\
**Created:** [November 11, 2004, 3:27am UTC](https://forum.kirupa.com/t/execute-final-code-on-window-close/70160 "2004-11-11T03:27:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mkeefe](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/mkeefe/32/513_2.png) [@mkeefe](https://forum.kirupa.com/u/mkeefe)\
**Post date:** [November 11, 2004, 3:27am UTC](https://forum.kirupa.com/t/execute-final-code-on-window-close/70160/1 "2004-11-11T03:27:51Z")

</div>

Hello,

I am looking for a way to have a piece of code executed when the user closes the browser window. Here is an example. I have a management program that the user logs into. If they “logout” the user is dropped from the database, but if the user just closes the browser they stay logged in. Any idea how I might get this to work?

-matt
