Skip to main content
Known Participant
May 20, 2009
Question

seting action on exit of page

  • May 20, 2009
  • 2 replies
  • 917 views

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

    This topic has been closed for replies.

    2 replies

    Simon.DauAuthor
    Known Participant
    May 21, 2009

    Thanks guys.

    Worked like charm

    Inspiring
    May 20, 2009

    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

    ilssac
    Inspiring
    May 20, 2009

    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.

    Inspiring
    May 20, 2009

    Sure did! Thanks, Ian. I'm typing with one hand due to a recently broken wrist and just moved too quickly through my post !