Detecting user leaving page

  • Thread starter Thread starter daveh551
  • Start date Start date
D

daveh551

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.
 
It's a client side event, not a server side (ASP .NET) event. It's simply
the unload event.
 
It's a client side event, not a server side (ASP .NET) event. It's simply
the unload event.

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.)
 
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.
 
Back
Top