Trigger a Custom Event when a Page is Unloading

Actually, I have noticed that file uploader leaves orphaned files if thing has not been created, so I decided to delete after user leave the page. I have tried the plugin, it does not work properly. I found this solution.