Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

seting action on exit of page

Community Beginner ,
May 20, 2009 May 20, 2009

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

856
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 20, 2009 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
May 20, 2009 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 20, 2009 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 !

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 21, 2009 May 21, 2009
LATEST

Thanks guys.

Worked like charm

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources