Detecting user leaving page

Discussion in 'ASP .Net' started by daveh551, Aug 5, 2008.

  1. daveh551

    daveh551 Guest

    Okay, I feel like this is probably a stupid question, but...

    I have accessed sites that are pushing some scam that, when you go to
    leave the page it will pop up a box saying, "No, don't go, let our
    live agent talk you into buying our junk."

    My question is, what event do they use to tell that you are leaving
    the page? Looking through the events available in the Page class, I
    see a lot that take place when the page is initiated, but nothing that
    is triggered when the user leaves.

    What am I missing?

    Thanks for your help.
     
    daveh551, Aug 5, 2008
    #1
    1. Advertisements

  2. They use a standard html event : Body_OnUnload.

    http://www.htmlcodetutorial.com/document/_BODY_onUnload.html



    Juan T. Llibre, asp.net MVP
    asp.net faq : http://asp.net.do/faq/
    foros de asp.net, en español : http://asp.net.do/foros/
    ======================================
    "daveh551" <> wrote in message news:...
    > Okay, I feel like this is probably a stupid question, but...
    >
    > I have accessed sites that are pushing some scam that, when you go to
    > leave the page it will pop up a box saying, "No, don't go, let our
    > live agent talk you into buying our junk."
    >
    > My question is, what event do they use to tell that you are leaving
    > the page? Looking through the events available in the Page class, I
    > see a lot that take place when the page is initiated, but nothing that
    > is triggered when the user leaves.
    >
    > What am I missing?
    >
    > Thanks for your help.
     
    Juan T. Llibre, Aug 5, 2008
    #2
    1. Advertisements

  3. daveh551

    Scott M. Guest

    It's a client side event, not a server side (ASP .NET) event. It's simply
    the unload event.


    "daveh551" <> wrote in message
    news:...
    > Okay, I feel like this is probably a stupid question, but...
    >
    > I have accessed sites that are pushing some scam that, when you go to
    > leave the page it will pop up a box saying, "No, don't go, let our
    > live agent talk you into buying our junk."
    >
    > My question is, what event do they use to tell that you are leaving
    > the page? Looking through the events available in the Page class, I
    > see a lot that take place when the page is initiated, but nothing that
    > is triggered when the user leaves.
    >
    > What am I missing?
    >
    > Thanks for your help.
     
    Scott M., Aug 5, 2008
    #3
  4. daveh551

    daveh551 Guest

    On Aug 4, 10:13 pm, "Scott M." <> wrote:
    > It's a client side event, not a server side (ASP .NET) event. It's simply
    > the unload event.
    >
    > "daveh551" <> wrote in message
    >
    > news:...
    >
    > > Okay, I feel like this is probably a stupid question, but...

    >
    > > I have accessed sites that are pushing some scam that, when you go to
    > > leave the page it will pop up a box saying, "No, don't go, let our
    > > live agent talk you into buying our junk."

    >
    > > My question is, what event do they use to tell that you are leaving
    > > the page? Looking through the events available in the Page class, I
    > > see a lot that take place when the page is initiated, but nothing that
    > > is triggered when the user leaves.

    >
    > > What am I missing?

    >
    > > Thanks for your help.


    Thanks, both of you. That makes sense.

    Follow on question, and dont feel compelled to answer it because Im
    sure I can dig a little and find the answer on my own, but what kind
    of javascript code would I write to reflect that event back to the
    server to do something with there?(I.e, I want to record the time the
    user spent on a page in a database for statistical analysis, so I need
    to record when they leave.)
     
    daveh551, Aug 6, 2008
    #4
  5. daveh551

    Scott M. Guest

    You could place an HTML hidden form field into the page and then update that
    field's value with the current time on the page's unload event.


    "daveh551" <> wrote in message
    news:...
    > On Aug 4, 10:13 pm, "Scott M." <> wrote:
    >> It's a client side event, not a server side (ASP .NET) event. It's
    >> simply
    >> the unload event.
    >>
    >> "daveh551" <> wrote in message
    >>
    >> news:...
    >>
    >> > Okay, I feel like this is probably a stupid question, but...

    >>
    >> > I have accessed sites that are pushing some scam that, when you go to
    >> > leave the page it will pop up a box saying, "No, don't go, let our
    >> > live agent talk you into buying our junk."

    >>
    >> > My question is, what event do they use to tell that you are leaving
    >> > the page? Looking through the events available in the Page class, I
    >> > see a lot that take place when the page is initiated, but nothing that
    >> > is triggered when the user leaves.

    >>
    >> > What am I missing?

    >>
    >> > Thanks for your help.

    >
    > Thanks, both of you. That makes sense.
    >
    > Follow on question, and dont feel compelled to answer it because Im
    > sure I can dig a little and find the answer on my own, but what kind
    > of javascript code would I write to reflect that event back to the
    > server to do something with there?(I.e, I want to record the time the
    > user spent on a page in a database for statistical analysis, so I need
    > to record when they leave.)
     
    Scott M., Aug 6, 2008
    #5
    1. Advertisements

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. Rich
    Replies:
    1
    Views:
    464
    bruce barker
    Feb 20, 2004
  2. Sacha Korell
    Replies:
    6
    Views:
    6,715
    MasterGaurav
    Mar 9, 2005
  3. Replies:
    7
    Views:
    26,731
    rohit.net100
    Feb 28, 2011
  4. Chris Roden
    Replies:
    4
    Views:
    680
    Mark Rae [MVP]
    Dec 13, 2007
  5. Andy
    Replies:
    4
    Views:
    1,092
    Cowboy \(Gregory A. Beamer\)
    Apr 28, 2008
  6. IVer Erling Årva

    Howto: Alert user when leaving a frame

    IVer Erling Årva, Jul 2, 2003, in forum: Javascript
    Replies:
    1
    Views:
    143
    Richard Cornford
    Jul 3, 2003
  7. Zvonko

    Capturing event user leaving page

    Zvonko, Sep 2, 2005, in forum: Javascript
    Replies:
    8
    Views:
    378
    ExGuardianReader
    Sep 10, 2005
  8. koruyucu
    Replies:
    2
    Views:
    294
    Thiago Macedo
    Jul 30, 2008
Loading...