# Run a script when the user closes the swf

**URL:** https://forum.kirupa.com/t/run-a-script-when-the-user-closes-the-swf/292217
**Category:** flash
**Created:** [July 11, 2009, 6:34pm UTC](https://forum.kirupa.com/t/run-a-script-when-the-user-closes-the-swf/292217 "2009-07-11T18:34:02Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Psykloak1](https://avatars.discourse-cdn.com/v4/letter/p/7ab992/32.png) [@Psykloak1](https://forum.kirupa.com/u/Psykloak1)
#### Post date: [July 11, 2009, 6:34pm UTC](https://forum.kirupa.com/t/run-a-script-when-the-user-closes-the-swf/292217/1 "2009-07-11T18:34:02Z")

</div>

Can you call a function when the user closes the browser window or navigates away from the page?

I’m making a cartoon, and I’m curious how long people watch it before closing the window or navigating away from the page. I could have it, every x seconds, report back the the server, and I can get a rough idea of how long they watched, but if it could report the exact time when the user closed it, I would know exactly.
