Copy link to clipboard
Copied
Is there any way to set an action on exit of the page?
I mean, in one window i'm uploading files to temp directory and if user presses 'correct' button it targets custom tag which deletes these files.
My concern is that if user will leave page without either pressing that 'correct' button or 'upload' button (Both deletes files) these files will be left in the server.
So is there any way to target my custom tag on exit of the page?
cheers,
Simon
Copy link to clipboard
Copied
This sounds like something you'll want JavaScript for. Check out the window.onload() method. It fires whenever a user tries to 'leave' your page (i.e., when a 'page' is unloaded from the browser).
Sample:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Unloading a Page</title>
<script type="text/javascript">
function unloaded(){
alert( 'you are leaving my page...' );
}
</script>
</head>
<body onunload="unloaded()">
<p>Hello World</p></body>
</html>
This is only meant as a skeleton to get you started!
Hope it helps,
Craig
Copy link to clipboard
Copied
craigkaminsky wrote:
Check out the window.onload() method.
I think you meant to suggest the window.onunload event as your code shows. Not the window.onload event which is fired when the pages loads at the beginning, not when the page unloads when the user leaves.
Copy link to clipboard
Copied
Sure did! Thanks, Ian. I'm typing with one hand due to a recently broken wrist and just moved too quickly through my post !
Copy link to clipboard
Copied
Thanks guys.
Worked like charm