Delete Server File When Exiting from Web Page
As Lajos Arpad wrote, you should send notification to the server when the page is unloaded (XmlHTTPRequest in onbeforeunload event for example); but beware, that it will not be bulletproof - for example if user resets his/her machine, or forces killing browser process ungracefully (unix kill -9 for example), the browser will cease to exist and will not send any notification to the server. Maybe in that case it would be the best to introduce some heartbeat, like the webpage sends XHR every 10 seconds, and if the server doesn't see any heartbeat in 5 minutes, it's likely that user died and the file should be deleted too.
Using a python cgi script and I have a form with both a Submit and Cancel button.  

When a user tries to leave the web page by clicking Cancel, closing the window or hitting the back button, I want to delete a file that exists on the server.  The file name is dependent on the values in the form.
When the user clicks the Submit button, no file will be deleted.  The form action is to take the user to another python cgi script.
I can catch the user leaving the page with  javascript onbeforeunload event, but I can't delete the files in javascript.  How do I delete the files?