Take the 2-minute tour ×  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?  share|improve
this question This sounds like you have a conceptional problem -
why not save the file after the user submits the form? –  l4mpi
Sep 24 '12 at 14:58 add comment  2 Answers  up vote 0 down vote
accepted  You can't access server files using Javascript because
of security reasons. However, you can make a postback in the
onbeforeunload event and on the server-side event (which handles
this postback