How to detect browser close

Discussion in 'ASP .Net' started by Lord2702, Oct 30, 2004.

  1. Lord2702

    Lord2702 Guest

    Sat. Oct. 30, 2004 3:25 PM PT

    I want to detect, if user has close the browser, (after logging to my site),
    that user has closed the browser. How to achieve it ? I want to know this
    close action on my server-side code. Because if he logout by clicking on
    Logout/ Sign-Off button it simple to get the message.

    Although, this is very similar to the first above. Also, if user takes any
    action on client-side or browser side how will I detect or send a message to
    server-side that user has taken xyzAction ?

    Thanks in Advance.
     
    Lord2702, Oct 30, 2004
    #1
    1. Advertising

  2. Lord2702

    Teemu Keiski Guest

    Point is that there is no 100% way to guarantee that. You can try having js
    scripts to send something to the server when browser gets closed or
    something else happens, but if user has disabled js, you are out of luck.
    You should design the app such that occasions like this are taken into
    account, you just can't help it.


    --
    Teemu Keiski
    MCP, Microsoft MVP (ASP.NET), AspInsiders member
    ASP.NET Forum Moderator, AspAlliance Columnist
    http://blogs.aspadvice.com/joteke




    "Lord2702" <> wrote in message
    news:...
    > Sat. Oct. 30, 2004 3:25 PM PT
    >
    > I want to detect, if user has close the browser, (after logging to my

    site),
    > that user has closed the browser. How to achieve it ? I want to know this
    > close action on my server-side code. Because if he logout by clicking on
    > Logout/ Sign-Off button it simple to get the message.
    >
    > Although, this is very similar to the first above. Also, if user takes any
    > action on client-side or browser side how will I detect or send a message

    to
    > server-side that user has taken xyzAction ?
    >
    > Thanks in Advance.
    >
    >
    >
     
    Teemu Keiski, Oct 31, 2004
    #2
    1. Advertising

  3. You should only respond on the session timing out, or the button being
    clicked - other than that assume that your client is still connected.

    --
    Regards

    John Timney
    Microsoft Regional Director
    Microsoft MVP

    "Lord2702" <> wrote in message
    news:...
    > Sat. Oct. 30, 2004 3:25 PM PT
    >
    > I want to detect, if user has close the browser, (after logging to my

    site),
    > that user has closed the browser. How to achieve it ? I want to know this
    > close action on my server-side code. Because if he logout by clicking on
    > Logout/ Sign-Off button it simple to get the message.
    >
    > Although, this is very similar to the first above. Also, if user takes any
    > action on client-side or browser side how will I detect or send a message

    to
    > server-side that user has taken xyzAction ?
    >
    > Thanks in Advance.
    >
    >
    >
     
    John Timney \(Microsoft MVP\), Oct 31, 2004
    #3
  4. Hi,

    As others have said this is a tricky issue. The odds of you getting a
    succesful postback are 50/50 to say the best. I've had about a 95% success
    rate doing this:

    1. Capture the onbeforeunload event in your body tag.
    2. Incorporate the WebService.htc.
    3. When the onbeforeunload event fires run a function that uses the
    WebService.htc to tell a web service.

    The browser will close before you get a response back but, about 95% of the
    time, your web service will get hit and the user can successfully be logged
    out. Note, that using the latest IE and Windows XP you will achieve almost
    100% results. This is sort of complicated until you get the hang of it. If
    this isn't something you want to try then here is another suggestion to
    improve your chances but it might seem clunky to the user:

    Have a main page that the user browses to. To run your app, they click a
    button or link and then you use window.open() to create a new browser
    window. This is the window your app runs from. Don't ask me why, but the
    success rate of a postback from onbeforeunload seems to be much higher for
    browsers launched from javascript than from browsers launched by the user.
    Good luck! Ken.

    --
    Ken Dopierala Jr.
    For great ASP.Net web hosting try:
    http://www.webhost4life.com/default.asp?refid=Spinlight
    If you sign up under me and need help, email me.

    "Lord2702" <> wrote in message
    news:...
    > Sat. Oct. 30, 2004 3:25 PM PT
    >
    > I want to detect, if user has close the browser, (after logging to my

    site),
    > that user has closed the browser. How to achieve it ? I want to know this
    > close action on my server-side code. Because if he logout by clicking on
    > Logout/ Sign-Off button it simple to get the message.
    >
    > Although, this is very similar to the first above. Also, if user takes any
    > action on client-side or browser side how will I detect or send a message

    to
    > server-side that user has taken xyzAction ?
    >
    > Thanks in Advance.
    >
    >
    >
     
    Ken Dopierala Jr., Oct 31, 2004
    #4
    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. sm mehta

    how to detect Browser close event.

    sm mehta, Jul 29, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    5,190
    Steve C. Orr, MCSD
    Jul 29, 2003
  2. Lord2702
    Replies:
    3
    Views:
    652
  3. Replies:
    7
    Views:
    11,977
  4. Iñaki Baz Castillo
    Replies:
    7
    Views:
    893
    Iñaki Baz Castillo
    Jan 12, 2010
  5. Replies:
    0
    Views:
    516
Loading...

Share This Page