Detect if browser closed

Discussion in 'ASP .Net' started by Chris, Apr 27, 2005.

  1. Chris

    Chris Guest

    Can anybody tell me how to detect is the user has closed the browser

    Thank you
     
    Chris, Apr 27, 2005
    #1
    1. Advertising

  2. Chris

    Patrice Guest

    If this is during a request try IsClientConnected.

    Else you have to callback the server when it happens (and in the case of a
    client side crash or if JS is disabled etc..., you'll never know the browser
    closed).

    Generally I try to design for not having to care... (you may want to explain
    what you want to do when the user closes the browser).

    Patrice

    --

    "Chris" <> a écrit dans le message de
    news:%...
    > Can anybody tell me how to detect is the user has closed the browser
    >
    > Thank you
    >
    >
     
    Patrice, Apr 27, 2005
    #2
    1. Advertising

  3. Chris

    Sambathraj Guest

    Hi,
    If Javascript is enabled in the client side, then you can use window.Closed
    property to check whether the window is close.
    For eg in Child window to check the parent window is closed you can use
    if(window.parent.closed)
    // do some thing

    Regards,
    Sambathraj
    "Chris" <> wrote in message
    news:%...
    > Can anybody tell me how to detect is the user has closed the browser
    >
    > Thank you
    >
    >
     
    Sambathraj, Apr 27, 2005
    #3
  4. Chris

    Chris Guest

    Ok what needs to have happen.
    when a user edits a record I am locking the record by a bit field.
    So if the user clicks the x on that edit screen I need detect that and
    unlock the record in the database.

    I am storing the locking by user session.sessionID.
    If you know of a way to get all session.sessionID's that would work for me
    too. I can run a check on that instead. Which is what I want to do.

    Thanks



    "Chris" <> wrote in message
    news:%...
    > Can anybody tell me how to detect is the user has closed the browser
    >
    > Thank you
    >
    >
     
    Chris, Apr 27, 2005
    #4
  5. Hi Chris,

    You can't tell when the browser has closed, as HTTP is stateless. That is
    why Sessions time out, and why there is a Session_End event handler in your
    global class. Assuming that your app can wait 20 minutes to perform this
    cleanup task, that's the place to do it.

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    ..Net Developer
    What You Seek Is What You Get.

    "Chris" <> wrote in message
    news:%...
    > Ok what needs to have happen.
    > when a user edits a record I am locking the record by a bit field.
    > So if the user clicks the x on that edit screen I need detect that and
    > unlock the record in the database.
    >
    > I am storing the locking by user session.sessionID.
    > If you know of a way to get all session.sessionID's that would work for me
    > too. I can run a check on that instead. Which is what I want to do.
    >
    > Thanks
    >
    >
    >
    > "Chris" <> wrote in message
    > news:%...
    >> Can anybody tell me how to detect is the user has closed the browser
    >>
    >> Thank you
    >>
    >>

    >
    >
     
    Kevin Spencer, Apr 27, 2005
    #5
  6. Chris

    Patrice Guest

    Are you sure you need exclusive locking ? Did you checked the optimistic
    approach ? What is the probability to have multiple people editing the same
    record at the same time ?
    You could also keep a datetime instead of just a bit field. It would allow
    to have a safety mecanism so that a long running lock could be discarded...

    If you really need you could trap onbeforeunload or onclose or a similar
    client side event to call a server side page to unlock the record.

    Patrice

    --

    "Chris" <> a écrit dans le message de
    news:%...
    > Ok what needs to have happen.
    > when a user edits a record I am locking the record by a bit field.
    > So if the user clicks the x on that edit screen I need detect that and
    > unlock the record in the database.
    >
    > I am storing the locking by user session.sessionID.
    > If you know of a way to get all session.sessionID's that would work for me
    > too. I can run a check on that instead. Which is what I want to do.
    >
    > Thanks
    >
    >
    >
    > "Chris" <> wrote in message
    > news:%...
    > > Can anybody tell me how to detect is the user has closed the browser
    > >
    > > Thank you
    > >
    > >

    >
    >
     
    Patrice, Apr 27, 2005
    #6
  7. Steve C. Orr [MVP, MCSD], Apr 27, 2005
    #7
  8. Chris

    Chris Guest

    Well I have gone another route. Just to let you all know.
    First off thanks for the info

    I am now using the system.web.cacheing.cache
    I store a dataset in there with a recordid and a recordtype

    now if the user closes his brower it will take about 5 mins for the
    application to unlock that record in the cache.


    "Chris" <> wrote in message
    news:%...
    > Can anybody tell me how to detect is the user has closed the browser
    >
    > Thank you
    >
    >
     
    Chris, Apr 27, 2005
    #8
    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. hb
    Replies:
    6
    Views:
    754
  2. NWx
    Replies:
    2
    Views:
    2,305
  3. news.microsoft.com
    Replies:
    2
    Views:
    494
    news.microsoft.com
    Dec 17, 2005
  4. Glen
    Replies:
    3
    Views:
    2,459
  5. Matt Kruse
    Replies:
    5
    Views:
    322
    Richard Cornford
    Sep 9, 2003
Loading...

Share This Page