SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast codlib's Avatar
    Join Date
    Jan 2007
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Running an ajax script at the time of closing the window

    hi friends,

    i have a problem with my website. i want to run a php file using ajax at the
    time of closing the browser. i have written the code and it is working correctly.
    i have used the javascript functon " window.onUnload " for tracking the close event. but the problem is this function will called every time i refreshes the window or i navigate to another link in the same site. i need only this function to run at the time of user closing the window or browser. friends, is there any solution for avoiding this or any other alternative?

    codlib

  2. #2
    SitePoint Evangelist jplush76's Avatar
    Join Date
    Nov 2003
    Location
    Los Angeles, CA
    Posts
    460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    http://www.codingforums.com/showthread.php?t=37279

    maybe that has something that would work for u
    My-Bic - Easiest AJAX/PHP Framework Around
    Now Debug PHP scripts with Firebug!

  3. #3
    SitePoint Enthusiast codlib's Avatar
    Join Date
    Jan 2007
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi

    i have tried the following code.... it is working correctly in IE. but not
    in mozilla... is there any other way?

    Code:
    <script language="javascript">
    function doUnload(e)
    {
     alert("onunload event fires.....");
     e= e||window.event;
     if (e.clientX < 0 && e.clientY < 0)
     {
       alert("Window is closing...");
     }
    }
    </script>
    HTML Code:
    <body onunload="doUnload();">


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •