onleave?

Discussion in 'HTML' started by Thomas Henz, Sep 7, 2003.

  1. Thomas Henz

    Thomas Henz Guest

    Hi!

    I'm searching for something that lets me write into a mysql db (or just
    do sth) when a user leaves a site. that means if the user closes the
    browser window. How can I do such a thing? I heard something about a
    <body onleave=""> but it doesn't seem to be implemented in browsers or
    at least some of them.

    Thanks,

    Tom
     
    Thomas Henz, Sep 7, 2003
    #1
    1. Advertising

  2. Thomas Henz wrote:

    > I'm searching for something that lets me write into a mysql db (or just
    > do sth) when a user leaves a site. that means if the user closes the
    > browser window. How can I do such a thing? I heard something about a
    > <body onleave=""> but it doesn't seem to be implemented in browsers or
    > at least some of them.


    You're probably thinking of onunload - but its useless for what you are
    planning.

    There is no effective way of doing anything on the server in responce to the
    user leaving a page.

    --
    David Dorward http://dorward.me.uk/
     
    David Dorward, Sep 7, 2003
    #2
    1. Advertising

  3. Thomas Henz wrote:
    > Hi!


    Hi!

    > I'm searching for something that lets me write into a mysql db (or
    > just do sth) when a user leaves a site. that means if the user
    > closes the browser window. How can I do such a thing?


    There's no reliable way to do this. HTTP is stateless, so once your
    server has filled the user's latest request, you have no way of
    knowing if they're viewing it, have closed their browser, have typed
    in a new URL and scooted off elsewhere, etc.

    About the best you can do is have a session on the server side for
    each user that expires after a certain period of inactivity: e.g.,
    after 10 minutes with no further requests in that session. When the
    session expires, you assume the user has "left the site" and do
    something accordingly. Cookies and/or hacked URLs are the usual means
    for tracking sessions.

    --
    Joel.
     
    Joel Shepherd, Sep 7, 2003
    #3
  4. Thomas Henz

    Thomas Henz Guest

    Joel Shepherd wrote:
    > About the best you can do is have a session on the server side for each
    > user that expires after a certain period of inactivity: e.g., after 10
    > minutes with no further requests in that session. When the session
    > expires, you assume the user has "left the site" and do something
    > accordingly. Cookies and/or hacked URLs are the usual means for tracking
    > sessions.


    How can I do that 10 minutes thing without access to mysql files on the
    providers side? or is that a php session thing (i smell OT)?

    tom
     
    Thomas Henz, Sep 7, 2003
    #4
  5. Thomas Henz wrote:
    > Joel Shepherd wrote:
    >
    >> About the best you can do is have a session on the server side
    >> for each user that expires after a certain period of inactivity:
    >> e.g., after 10 minutes with no further requests in that session.

    >
    > How can I do that 10 minutes thing without access to mysql files on
    > the providers side? or is that a php session thing (i smell OT)?


    It's probably a PHP thing. Hopefully PHP has some way of notifying you
    (in code) when a session has expired. Catch that notification, write
    something to your database, and move on.

    I'm being vague because I haven't used PHP specifically, and in any
    event sessions can be and are implemented in many different ways.

    --
    Joel.
     
    Joel Shepherd, Sep 7, 2003
    #5
  6. Thomas Henz <> wrote in news:bjg2fd$i3g$04$-
    online.com:

    > Hi!
    >
    > I'm searching for something that lets me write into a mysql db (or just
    > do sth) when a user leaves a site. that means if the user closes the
    > browser window. How can I do such a thing? I heard something about a
    > <body onleave=""> but it doesn't seem to be implemented in browsers or
    > at least some of them.
    >
    > Thanks,
    >
    > Tom
    >


    I don't think there is a way to this within php. My thought is that you
    could start a session and log the session-id into mysql for every page
    access, then have a cron job that checks for sessions within mysql that
    have been inactive for a short while. If it finds one, kill the session and
    remove the mysql row. But it seems like an awful lot of work.

    The other thing (*shudder*) is to use javascript's onblur or onclose and
    open a pop-up to a short php script that does the save, but I wouldn't
    recommend it. Pop-ups for such a purpose would be a bit rude! :)

    GL...

    --
    D Benfer
    Mokee.com
    USWebSales.com
     
    Darren Benfer, Sep 8, 2003
    #6
  7. Thomas Henz

    Thomas Henz Guest

    Darren Benfer wrote:

    > The other thing (*shudder*) is to use javascript's onblur or onclose and
    > open a pop-up to a short php script that does the save, but I wouldn't
    > recommend it. Pop-ups for such a purpose would be a bit rude! :)


    I thought about that for some minutes and came to the same conclusion of
    being rude to the user. But since I don't have access to a root server
    or sth where I could install automatic scripts...well...why not be rude? :)
    Couldn't I open a new window and close it immediately after executing
    the sql command? Something like "when function finished, window.close()"? :/

    Tom
     
    Thomas Henz, Sep 8, 2003
    #7
  8. Thomas Henz

    Chris Morris Guest

    Thomas Henz <> writes:
    > I thought about that for some minutes and came to the same conclusion
    > of being rude to the user. But since I don't have access to a root
    > server or sth where I could install automatic scripts...well...why not
    > be rude? :)


    You could just assume that they've left when the session isn't being
    used anymore.

    > Couldn't I open a new window and close it immediately after executing
    > the sql command? Something like "when function finished,
    > window.close()"? :/


    Depending on the speed of the user's computer, this might get in the
    way anyway.

    Also, pop-up blockers are becoming more commonplace - built in to most
    modern browsers, 3rd party ones available for older browsers such as IE.

    --
    Chris
     
    Chris Morris, Sep 8, 2003
    #8
  9. "Thomas Henz" <> wrote in message
    news:bjh7ij$hev$02$-online.com...
    > or sth


    ????

    --
    Andrew Davidson
     
    Andrew Davidson, Sep 8, 2003
    #9
  10. Thomas Henz

    Thomas Henz Guest

    Andrew Davidson wrote:

    > "Thomas Henz" <> wrote in message
    > news:bjh7ij$hev$02$-online.com...
    >
    >>or sth

    >
    >
    > ????
    >

    sth=something :/

    What I wanted to say is that I don't have access to a server shell or
    cronjobs etc. that could do things automatically for me.
     
    Thomas Henz, Sep 8, 2003
    #10
  11. Thomas Henz <> wrote in
    news:bjh7ij$hev$02$-online.com:

    > Darren Benfer wrote:
    >
    >> The other thing (*shudder*) is to use javascript's onblur or onclose
    >> and open a pop-up to a short php script that does the save, but I
    >> wouldn't recommend it. Pop-ups for such a purpose would be a bit
    >> rude! :)

    >
    > I thought about that for some minutes and came to the same conclusion
    > of being rude to the user. But since I don't have access to a root
    > server or sth where I could install automatic scripts...well...why not
    > be rude? :) Couldn't I open a new window and close it immediately
    > after executing the sql command? Something like "when function
    > finished, window.close()"? :/
    >
    > Tom
    >
    >


    Yep!

    (And I'm crossposting this to alt.php in case you need any other php
    help)

    Here's the pseudo-code (untested):

    NORMAL PAGE CODE:
    <html>
    <body onClose="window.open('database_operation.php');">
    <!-- page stuff -->
    </body>
    </html>

    DATABSE_OPERATION.PHP CODE:
    <?php
    // do database stuff
    if (database stuff done) {
    echo "<html><body onLoad=\"window.close();\">";
    echo "</body></html>";
    exit;
    } else {
    die("Database error! Closing script.");
    }
    ?>

    You might need something other that onClose (onBlur?) Real raw, but hope
    it helps...

    --
    D Benfer
    Mokee.com
    USWebSales.com
     
    Darren Benfer, Sep 8, 2003
    #11
  12. Thomas Henz <> wrote in news:bjhoav$e3d$03$-
    online.com:

    > Andrew Davidson wrote:
    >
    >> "Thomas Henz" <> wrote in message
    >> news:bjh7ij$hev$02$-online.com...
    >>
    >>>or sth

    >>
    >>
    >> ????
    >>

    > sth=something :/
    >
    > What I wanted to say is that I don't have access to a server shell or
    > cronjobs etc. that could do things automatically for me.
    >
    >


    In that case this might be the best way. (so long as the person has
    javascript on...)

    GL!

    --
    D Benfer
    Mokee.com
    USWebSales.com
     
    Darren Benfer, Sep 8, 2003
    #12
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?TUw=?=

    OnLeave event on a textbox?

    =?Utf-8?B?TUw=?=, Sep 27, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    6,993
    Marina
    Sep 27, 2005
  2. =?Utf-8?B?QmVuIEZpZGdl?=

    Is there a client-side OnLeave event for a page?

    =?Utf-8?B?QmVuIEZpZGdl?=, Feb 13, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    609
    Karl Seguin [MVP]
    Feb 13, 2006
Loading...

Share This Page