Detecting user leaving page

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.
 
S

Scott M.

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

daveh551

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.)
 
S

Scott M.

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top