SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Guru
    Join Date
    Mar 2002
    Posts
    608
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Stupid OnUnload - page visit duration Question

    Hello,

    I was wondering if there is a way, without using exit popups, to submit to a database using onUnload when a visitor leaves a web page. The reason is I want to track the last moment somebody is on a page before they leave the domain entirely (I can determine the last page, so that's not a factor)

    Problem is, I want to know if Onunload can actually perform a command such as submit a form or hit a pixelated tracking script that is invisible to the user as they leave the page?

    I know javascript can track page duration, but if one leaves the domain, how does it know when they left, is what I am asking. Thanks

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)

    length of stay

    As long as the user doesn't mess with the javascript or their time settings you could use js to get the time on page load and on page unload and POST the info to a page using hidden fields.

  3. #3
    SitePoint Guru
    Join Date
    Mar 2002
    Posts
    608
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How do I do that? is it happening after they exit?

    So if I have a hidden form posting to response.php, with the value of the current time and first visit time, their exit would allow unload to submit?

    I just want to make sure. I certainly don't want to use refresh (at least a visible one) or popups, so I just have to make sure.

    Thanks for your time and forgive my ignorance.

  4. #4
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)

    onunload

    You could modify something like this to submit the POST info
    HTML Code:
    <html>
    <head>
    <script type="text/javascript">
    function winUnload(){
    alert("Unloading Window");
    }
    window.onunload = winUnload;
    </script>
    </head>
    <body>
    if you go, this page unloads <a href="http://www.sitepoint.com">Sitepoint</a>
    </body>
    </html>
    The script will run after the user "leaves" the page but before the browser closes it.

  5. #5
    SitePoint Guru
    Join Date
    Mar 2002
    Posts
    608
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So in place of "alert ("unloading Window") I just have the form
    submit? Interesting.
    Last edited by jbh; Oct 28, 2006 at 13:49.

  6. #6
    SitePoint Guru
    Join Date
    Mar 2002
    Posts
    608
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually, I am a dope. It doesn't because if I use onsubmit it lands them on the submission page.

    How do I physically insert that last bit of data without them going to the submit page or use a popup?

    Does anybody know?


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
  •