Help: How to detect if the browser is closed?

Discussion in 'ASP .Net' started by hb, Nov 17, 2003.

  1. hb

    hb Guest

    Hi,

    Would you please tell me how to detect if the client's browser is closed?

    I need such event to trigger a database modification.

    Thank you

    hb
     
    hb, Nov 17, 2003
    #1
    1. Advertising

  2. Hi,

    For the most part, your server will never know when the client browser is
    closed. Here are some very limited things you can do to tell if the client
    is still on your page (whether open or closed)

    While your server is processing a request, if it takes a long time to
    service that request, you can call Response.IsClientConnected to see if the
    browser is still on your page.

    You can add code to your page's client onunload event which could notify
    your server that the page is unloading. This will not tell you if the
    browser is being closed.
    For example: <body onunload="alert('closing');">

    If you use this method, use showModalDialog to browse to a page which
    notifies your server. That page will return JavaScript back to the dialog
    with window.close();.

    Another option is that you could write an ActiveX control. However, that
    control will only exist so long as the user is on your page. You still
    won't know if they close the browser.

    Essentially, the internet was designed such that the server only knows
    about the browser while it is processing a request from the browser. The
    rest of the time, the server is not aware of the browser.

    Does this answer your question?

    Thank you, Mike
    Microsoft, ASP.NET Support Professional

    Microsoft highly recommends to all of our customers that they visit the
    http://www.microsoft.com/protect site and perform the three straightforward
    steps listed to improve your computer's security.

    This posting is provided "AS IS", with no warranties, and confers no rights.


    --------------------
    > From: "hb" <>
    > Subject: Help: How to detect if the browser is closed?
    > Date: Mon, 17 Nov 2003 09:09:01 -0500
    > Lines: 11
    > X-Priority: 3
    > X-MSMail-Priority: Normal
    > X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
    > X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
    > Message-ID: <>
    > Newsgroups: microsoft.public.dotnet.framework.aspnet
    > NNTP-Posting-Host: x403446fe.ip.e-nt.net 64.52.70.254
    > Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
    > Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:191366
    > X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    >
    > Hi,
    >
    > Would you please tell me how to detect if the client's browser is closed?
    >
    > I need such event to trigger a database modification.
    >
    > Thank you
    >
    > hb
    >
    >
    >
     
    Mike Moore [MSFT], Nov 17, 2003
    #2
    1. Advertising

  3. hb

    hb Guest

    Hi, Mike,

    Thank you for the help.

    Would you please tell me where should I put
    if(Response.IsClientConnected)
    {
    //do something
    }

    Thank you

    hb
    ""Mike Moore [MSFT]"" <> wrote in message
    news:H$...
    > Hi,
    >
    > For the most part, your server will never know when the client browser is
    > closed. Here are some very limited things you can do to tell if the client
    > is still on your page (whether open or closed)
    >
    > While your server is processing a request, if it takes a long time to
    > service that request, you can call Response.IsClientConnected to see if

    the
    > browser is still on your page.
    >
    > You can add code to your page's client onunload event which could notify
    > your server that the page is unloading. This will not tell you if the
    > browser is being closed.
    > For example: <body onunload="alert('closing');">
    >
    > If you use this method, use showModalDialog to browse to a page which
    > notifies your server. That page will return JavaScript back to the dialog
    > with window.close();.
    >
    > Another option is that you could write an ActiveX control. However, that
    > control will only exist so long as the user is on your page. You still
    > won't know if they close the browser.
    >
    > Essentially, the internet was designed such that the server only knows
    > about the browser while it is processing a request from the browser. The
    > rest of the time, the server is not aware of the browser.
    >
    > Does this answer your question?
    >
    > Thank you, Mike
    > Microsoft, ASP.NET Support Professional
    >
    > Microsoft highly recommends to all of our customers that they visit the
    > http://www.microsoft.com/protect site and perform the three

    straightforward
    > steps listed to improve your computer's security.
    >
    > This posting is provided "AS IS", with no warranties, and confers no

    rights.
    >
    >
    > --------------------
    > > From: "hb" <>
    > > Subject: Help: How to detect if the browser is closed?
    > > Date: Mon, 17 Nov 2003 09:09:01 -0500
    > > Lines: 11
    > > X-Priority: 3
    > > X-MSMail-Priority: Normal
    > > X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
    > > X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
    > > Message-ID: <>
    > > Newsgroups: microsoft.public.dotnet.framework.aspnet
    > > NNTP-Posting-Host: x403446fe.ip.e-nt.net 64.52.70.254
    > > Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
    > > Xref: cpmsftngxa06.phx.gbl

    microsoft.public.dotnet.framework.aspnet:191366
    > > X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    > >
    > > Hi,
    > >
    > > Would you please tell me how to detect if the client's browser is

    closed?
    > >
    > > I need such event to trigger a database modification.
    > >
    > > Thank you
    > >
    > > hb
    > >
    > >
    > >

    >
     
    hb, Nov 17, 2003
    #3
  4. Hi,

    Here's an article that describes usage of IsClientConnected and includes a
    code sample. It's old ASP code, but the concept remains the same.

    182892 HOWTO: Use IsClientConnected to Check If Browser Is Connected
    http://kb/article.asp?id=Q182892

    Thank you, Mike
    Microsoft, ASP.NET Support Professional

    Microsoft highly recommends to all of our customers that they visit the
    http://www.microsoft.com/protect site and perform the three straightforward
    steps listed to improve your computer’s security.

    This posting is provided "AS IS", with no warranties, and confers no rights.


    --------------------
    > From: "hb" <>
    > References: <>

    <H$>
    > Subject: Re: Help: How to detect if the browser is closed?
    > Date: Mon, 17 Nov 2003 16:52:19 -0500
    > Lines: 90
    > X-Priority: 3
    > X-MSMail-Priority: Normal
    > X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
    > X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
    > Message-ID: <>
    > Newsgroups: microsoft.public.dotnet.framework.aspnet
    > NNTP-Posting-Host: x403446fe.ip.e-nt.net 64.52.70.254
    > Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
    > Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:191530
    > X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    >
    > Hi, Mike,
    >
    > Thank you for the help.
    >
    > Would you please tell me where should I put
    > if(Response.IsClientConnected)
    > {
    > //do something
    > }
    >
    > Thank you
    >
    > hb
    > ""Mike Moore [MSFT]"" <> wrote in message
    > news:H$...
    > > Hi,
    > >
    > > For the most part, your server will never know when the client browser

    is
    > > closed. Here are some very limited things you can do to tell if the

    client
    > > is still on your page (whether open or closed)
    > >
    > > While your server is processing a request, if it takes a long time to
    > > service that request, you can call Response.IsClientConnected to see if

    > the
    > > browser is still on your page.
    > >
    > > You can add code to your page's client onunload event which could notify
    > > your server that the page is unloading. This will not tell you if the
    > > browser is being closed.
    > > For example: <body onunload="alert('closing');">
    > >
    > > If you use this method, use showModalDialog to browse to a page which
    > > notifies your server. That page will return JavaScript back to the

    dialog
    > > with window.close();.
    > >
    > > Another option is that you could write an ActiveX control. However, that
    > > control will only exist so long as the user is on your page. You still
    > > won't know if they close the browser.
    > >
    > > Essentially, the internet was designed such that the server only knows
    > > about the browser while it is processing a request from the browser. The
    > > rest of the time, the server is not aware of the browser.
    > >
    > > Does this answer your question?
    > >
    > > Thank you, Mike
    > > Microsoft, ASP.NET Support Professional
    > >
    > > Microsoft highly recommends to all of our customers that they visit the
    > > http://www.microsoft.com/protect site and perform the three

    > straightforward
    > > steps listed to improve your computer's security.
    > >
    > > This posting is provided "AS IS", with no warranties, and confers no

    > rights.
    > >
    > >
    > > --------------------
    > > > From: "hb" <>
    > > > Subject: Help: How to detect if the browser is closed?
    > > > Date: Mon, 17 Nov 2003 09:09:01 -0500
    > > > Lines: 11
    > > > X-Priority: 3
    > > > X-MSMail-Priority: Normal
    > > > X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
    > > > X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
    > > > Message-ID: <>
    > > > Newsgroups: microsoft.public.dotnet.framework.aspnet
    > > > NNTP-Posting-Host: x403446fe.ip.e-nt.net 64.52.70.254
    > > > Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
    > > > Xref: cpmsftngxa06.phx.gbl

    > microsoft.public.dotnet.framework.aspnet:191366
    > > > X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    > > >
    > > > Hi,
    > > >
    > > > Would you please tell me how to detect if the client's browser is

    > closed?
    > > >
    > > > I need such event to trigger a database modification.
    > > >
    > > > Thank you
    > > >
    > > > hb
    > > >
    > > >
    > > >

    > >

    >
    >
    >
     
    Mike Moore [MSFT], Nov 18, 2003
    #4
  5. hb

    hb Guest

    Hi, Mike,

    I have tried the method provided by the article Q182892.

    The IsClientConnect will become false when either the browser is closed or
    the user is redirected to another URL. I tried to use Request.Url to catch
    the
    new URL after IsClientConnect=false, but the URL I caught stay the same.

    Plus, the process uses about 70% CPU. So this method cannot be use in
    production code.

    What I am looking for is a way that can allow me to detect if the browser
    gets closed or
    if user gets redirected to another URL that has different domain. The result
    of such detection
    triggers a modification in database.

    Would you please give me some ideas?

    Thank you

    hb
    ""Mike Moore [MSFT]"" <> wrote in message
    news:...
    > Hi,
    >
    > Here's an article that describes usage of IsClientConnected and includes a
    > code sample. It's old ASP code, but the concept remains the same.
    >
    > 182892 HOWTO: Use IsClientConnected to Check If Browser Is Connected
    > http://kb/article.asp?id=Q182892
    >
    > Thank you, Mike
    > Microsoft, ASP.NET Support Professional
    >
    > Microsoft highly recommends to all of our customers that they visit the
    > http://www.microsoft.com/protect site and perform the three

    straightforward
    > steps listed to improve your computer's security.
    >
    > This posting is provided "AS IS", with no warranties, and confers no

    rights.
    >
    >
    > --------------------
    > > From: "hb" <>
    > > References: <>

    > <H$>
    > > Subject: Re: Help: How to detect if the browser is closed?
    > > Date: Mon, 17 Nov 2003 16:52:19 -0500
    > > Lines: 90
    > > X-Priority: 3
    > > X-MSMail-Priority: Normal
    > > X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
    > > X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
    > > Message-ID: <>
    > > Newsgroups: microsoft.public.dotnet.framework.aspnet
    > > NNTP-Posting-Host: x403446fe.ip.e-nt.net 64.52.70.254
    > > Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
    > > Xref: cpmsftngxa06.phx.gbl

    microsoft.public.dotnet.framework.aspnet:191530
    > > X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    > >
    > > Hi, Mike,
    > >
    > > Thank you for the help.
    > >
    > > Would you please tell me where should I put
    > > if(Response.IsClientConnected)
    > > {
    > > //do something
    > > }
    > >
    > > Thank you
    > >
    > > hb
    > > ""Mike Moore [MSFT]"" <> wrote in message
    > > news:H$...
    > > > Hi,
    > > >
    > > > For the most part, your server will never know when the client browser

    > is
    > > > closed. Here are some very limited things you can do to tell if the

    > client
    > > > is still on your page (whether open or closed)
    > > >
    > > > While your server is processing a request, if it takes a long time to
    > > > service that request, you can call Response.IsClientConnected to see

    if
    > > the
    > > > browser is still on your page.
    > > >
    > > > You can add code to your page's client onunload event which could

    notify
    > > > your server that the page is unloading. This will not tell you if the
    > > > browser is being closed.
    > > > For example: <body onunload="alert('closing');">
    > > >
    > > > If you use this method, use showModalDialog to browse to a page which
    > > > notifies your server. That page will return JavaScript back to the

    > dialog
    > > > with window.close();.
    > > >
    > > > Another option is that you could write an ActiveX control. However,

    that
    > > > control will only exist so long as the user is on your page. You still
    > > > won't know if they close the browser.
    > > >
    > > > Essentially, the internet was designed such that the server only knows
    > > > about the browser while it is processing a request from the browser.

    The
    > > > rest of the time, the server is not aware of the browser.
    > > >
    > > > Does this answer your question?
    > > >
    > > > Thank you, Mike
    > > > Microsoft, ASP.NET Support Professional
    > > >
    > > > Microsoft highly recommends to all of our customers that they visit

    the
    > > > http://www.microsoft.com/protect site and perform the three

    > > straightforward
    > > > steps listed to improve your computer's security.
    > > >
    > > > This posting is provided "AS IS", with no warranties, and confers no

    > > rights.
    > > >
    > > >
    > > > --------------------
    > > > > From: "hb" <>
    > > > > Subject: Help: How to detect if the browser is closed?
    > > > > Date: Mon, 17 Nov 2003 09:09:01 -0500
    > > > > Lines: 11
    > > > > X-Priority: 3
    > > > > X-MSMail-Priority: Normal
    > > > > X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
    > > > > X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
    > > > > Message-ID: <>
    > > > > Newsgroups: microsoft.public.dotnet.framework.aspnet
    > > > > NNTP-Posting-Host: x403446fe.ip.e-nt.net 64.52.70.254
    > > > > Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
    > > > > Xref: cpmsftngxa06.phx.gbl

    > > microsoft.public.dotnet.framework.aspnet:191366
    > > > > X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    > > > >
    > > > > Hi,
    > > > >
    > > > > Would you please tell me how to detect if the client's browser is

    > > closed?
    > > > >
    > > > > I need such event to trigger a database modification.
    > > > >
    > > > > Thank you
    > > > >
    > > > > hb
    > > > >
    > > > >
    > > > >
    > > >

    > >
    > >
    > >

    >
     
    hb, Nov 19, 2003
    #5
  6. Hi,

    The internet (specifically the HTTP protocol) does not allow the server to
    keep watch over the client. The things I've mentioned are what is available
    for watching the client.

    Thank you, Mike
    Microsoft, ASP.NET Support Professional

    Microsoft highly recommends to all of our customers that they visit the
    http://www.microsoft.com/protect site and perform the three straightforward
    steps listed to improve your computer’s security.

    This posting is provided "AS IS", with no warranties, and confers no rights.


    --------------------
    > From: "hb" <>
    > References: <>

    <H$>
    <>
    <>
    > Subject: Re: Help: How to detect if the browser is closed?
    > Date: Wed, 19 Nov 2003 10:41:06 -0500
    > Lines: 166
    > X-Priority: 3
    > X-MSMail-Priority: Normal
    > X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
    > X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
    > Message-ID: <>
    > Newsgroups: microsoft.public.dotnet.framework.aspnet
    > NNTP-Posting-Host: x403446fe.ip.e-nt.net 64.52.70.254
    > Path:

    cpmsftngxa07.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08
    ..phx.gbl!TK2MSFTNGP12.phx.gbl
    > Xref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.framework.aspnet:191249
    > X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    >
    > Hi, Mike,
    >
    > I have tried the method provided by the article Q182892.
    >
    > The IsClientConnect will become false when either the browser is closed or
    > the user is redirected to another URL. I tried to use Request.Url to catch
    > the
    > new URL after IsClientConnect=false, but the URL I caught stay the same.
    >
    > Plus, the process uses about 70% CPU. So this method cannot be use in
    > production code.
    >
    > What I am looking for is a way that can allow me to detect if the browser
    > gets closed or
    > if user gets redirected to another URL that has different domain. The

    result
    > of such detection
    > triggers a modification in database.
    >
    > Would you please give me some ideas?
    >
    > Thank you
    >
    > hb
    > ""Mike Moore [MSFT]"" <> wrote in message
    > news:...
    > > Hi,
    > >
    > > Here's an article that describes usage of IsClientConnected and

    includes a
    > > code sample. It's old ASP code, but the concept remains the same.
    > >
    > > 182892 HOWTO: Use IsClientConnected to Check If Browser Is Connected
    > > http://kb/article.asp?id=Q182892
    > >
    > > Thank you, Mike
    > > Microsoft, ASP.NET Support Professional
    > >
    > > Microsoft highly recommends to all of our customers that they visit the
    > > http://www.microsoft.com/protect site and perform the three

    > straightforward
    > > steps listed to improve your computer's security.
    > >
    > > This posting is provided "AS IS", with no warranties, and confers no

    > rights.
    > >
    > >
    > > --------------------
    > > > From: "hb" <>
    > > > References: <>

    > > <H$>
    > > > Subject: Re: Help: How to detect if the browser is closed?
    > > > Date: Mon, 17 Nov 2003 16:52:19 -0500
    > > > Lines: 90
    > > > X-Priority: 3
    > > > X-MSMail-Priority: Normal
    > > > X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
    > > > X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
    > > > Message-ID: <>
    > > > Newsgroups: microsoft.public.dotnet.framework.aspnet
    > > > NNTP-Posting-Host: x403446fe.ip.e-nt.net 64.52.70.254
    > > > Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
    > > > Xref: cpmsftngxa06.phx.gbl

    > microsoft.public.dotnet.framework.aspnet:191530
    > > > X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    > > >
    > > > Hi, Mike,
    > > >
    > > > Thank you for the help.
    > > >
    > > > Would you please tell me where should I put
    > > > if(Response.IsClientConnected)
    > > > {
    > > > //do something
    > > > }
    > > >
    > > > Thank you
    > > >
    > > > hb
    > > > ""Mike Moore [MSFT]"" <> wrote in message
    > > > news:H$...
    > > > > Hi,
    > > > >
    > > > > For the most part, your server will never know when the client

    browser
    > > is
    > > > > closed. Here are some very limited things you can do to tell if the

    > > client
    > > > > is still on your page (whether open or closed)
    > > > >
    > > > > While your server is processing a request, if it takes a long time

    to
    > > > > service that request, you can call Response.IsClientConnected to see

    > if
    > > > the
    > > > > browser is still on your page.
    > > > >
    > > > > You can add code to your page's client onunload event which could

    > notify
    > > > > your server that the page is unloading. This will not tell you if

    the
    > > > > browser is being closed.
    > > > > For example: <body onunload="alert('closing');">
    > > > >
    > > > > If you use this method, use showModalDialog to browse to a page

    which
    > > > > notifies your server. That page will return JavaScript back to the

    > > dialog
    > > > > with window.close();.
    > > > >
    > > > > Another option is that you could write an ActiveX control. However,

    > that
    > > > > control will only exist so long as the user is on your page. You

    still
    > > > > won't know if they close the browser.
    > > > >
    > > > > Essentially, the internet was designed such that the server only

    knows
    > > > > about the browser while it is processing a request from the browser.

    > The
    > > > > rest of the time, the server is not aware of the browser.
    > > > >
    > > > > Does this answer your question?
    > > > >
    > > > > Thank you, Mike
    > > > > Microsoft, ASP.NET Support Professional
    > > > >
    > > > > Microsoft highly recommends to all of our customers that they visit

    > the
    > > > > http://www.microsoft.com/protect site and perform the three
    > > > straightforward
    > > > > steps listed to improve your computer's security.
    > > > >
    > > > > This posting is provided "AS IS", with no warranties, and confers no
    > > > rights.
    > > > >
    > > > >
    > > > > --------------------
    > > > > > From: "hb" <>
    > > > > > Subject: Help: How to detect if the browser is closed?
    > > > > > Date: Mon, 17 Nov 2003 09:09:01 -0500
    > > > > > Lines: 11
    > > > > > X-Priority: 3
    > > > > > X-MSMail-Priority: Normal
    > > > > > X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
    > > > > > X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
    > > > > > Message-ID: <>
    > > > > > Newsgroups: microsoft.public.dotnet.framework.aspnet
    > > > > > NNTP-Posting-Host: x403446fe.ip.e-nt.net 64.52.70.254
    > > > > > Path:

    cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
    > > > > > Xref: cpmsftngxa06.phx.gbl
    > > > microsoft.public.dotnet.framework.aspnet:191366
    > > > > > X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    > > > > >
    > > > > > Hi,
    > > > > >
    > > > > > Would you please tell me how to detect if the client's browser is
    > > > closed?
    > > > > >
    > > > > > I need such event to trigger a database modification.
    > > > > >
    > > > > > Thank you
    > > > > >
    > > > > > hb
    > > > > >
    > > > > >
    > > > > >
    > > > >
    > > >
    > > >
    > > >

    > >

    >
    >
    >
     
    Mike Moore [MSFT], Nov 19, 2003
    #6
  7. hb

    hb Guest

    I got it.

    Thank you for the help!

    hb
    ""Mike Moore [MSFT]"" <> wrote in message
    news:...
    > Hi,
    >
    > The internet (specifically the HTTP protocol) does not allow the server to
    > keep watch over the client. The things I've mentioned are what is

    available
    > for watching the client.
    >
    > Thank you, Mike
    > Microsoft, ASP.NET Support Professional
    >
    > Microsoft highly recommends to all of our customers that they visit the
    > http://www.microsoft.com/protect site and perform the three

    straightforward
    > steps listed to improve your computer's security.
    >
    > This posting is provided "AS IS", with no warranties, and confers no

    rights.
    >
    >
    > --------------------
    > > From: "hb" <>
    > > References: <>

    > <H$>
    > <>
    > <>
    > > Subject: Re: Help: How to detect if the browser is closed?
    > > Date: Wed, 19 Nov 2003 10:41:06 -0500
    > > Lines: 166
    > > X-Priority: 3
    > > X-MSMail-Priority: Normal
    > > X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
    > > X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
    > > Message-ID: <>
    > > Newsgroups: microsoft.public.dotnet.framework.aspnet
    > > NNTP-Posting-Host: x403446fe.ip.e-nt.net 64.52.70.254
    > > Path:

    >

    cpmsftngxa07.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08
    > phx.gbl!TK2MSFTNGP12.phx.gbl
    > > Xref: cpmsftngxa07.phx.gbl

    microsoft.public.dotnet.framework.aspnet:191249
    > > X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    > >
    > > Hi, Mike,
    > >
    > > I have tried the method provided by the article Q182892.
    > >
    > > The IsClientConnect will become false when either the browser is closed

    or
    > > the user is redirected to another URL. I tried to use Request.Url to

    catch
    > > the
    > > new URL after IsClientConnect=false, but the URL I caught stay the same.
    > >
    > > Plus, the process uses about 70% CPU. So this method cannot be use in
    > > production code.
    > >
    > > What I am looking for is a way that can allow me to detect if the

    browser
    > > gets closed or
    > > if user gets redirected to another URL that has different domain. The

    > result
    > > of such detection
    > > triggers a modification in database.
    > >
    > > Would you please give me some ideas?
    > >
    > > Thank you
    > >
    > > hb
    > > ""Mike Moore [MSFT]"" <> wrote in message
    > > news:...
    > > > Hi,
    > > >
    > > > Here's an article that describes usage of IsClientConnected and

    > includes a
    > > > code sample. It's old ASP code, but the concept remains the same.
    > > >
    > > > 182892 HOWTO: Use IsClientConnected to Check If Browser Is Connected
    > > > http://kb/article.asp?id=Q182892
    > > >
    > > > Thank you, Mike
    > > > Microsoft, ASP.NET Support Professional
    > > >
    > > > Microsoft highly recommends to all of our customers that they visit

    the
    > > > http://www.microsoft.com/protect site and perform the three

    > > straightforward
    > > > steps listed to improve your computer's security.
    > > >
    > > > This posting is provided "AS IS", with no warranties, and confers no

    > > rights.
    > > >
    > > >
    > > > --------------------
    > > > > From: "hb" <>
    > > > > References: <>
    > > > <H$>
    > > > > Subject: Re: Help: How to detect if the browser is closed?
    > > > > Date: Mon, 17 Nov 2003 16:52:19 -0500
    > > > > Lines: 90
    > > > > X-Priority: 3
    > > > > X-MSMail-Priority: Normal
    > > > > X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
    > > > > X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
    > > > > Message-ID: <>
    > > > > Newsgroups: microsoft.public.dotnet.framework.aspnet
    > > > > NNTP-Posting-Host: x403446fe.ip.e-nt.net 64.52.70.254
    > > > > Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
    > > > > Xref: cpmsftngxa06.phx.gbl

    > > microsoft.public.dotnet.framework.aspnet:191530
    > > > > X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    > > > >
    > > > > Hi, Mike,
    > > > >
    > > > > Thank you for the help.
    > > > >
    > > > > Would you please tell me where should I put
    > > > > if(Response.IsClientConnected)
    > > > > {
    > > > > //do something
    > > > > }
    > > > >
    > > > > Thank you
    > > > >
    > > > > hb
    > > > > ""Mike Moore [MSFT]"" <> wrote in message
    > > > > news:H$...
    > > > > > Hi,
    > > > > >
    > > > > > For the most part, your server will never know when the client

    > browser
    > > > is
    > > > > > closed. Here are some very limited things you can do to tell if

    the
    > > > client
    > > > > > is still on your page (whether open or closed)
    > > > > >
    > > > > > While your server is processing a request, if it takes a long time

    > to
    > > > > > service that request, you can call Response.IsClientConnected to

    see
    > > if
    > > > > the
    > > > > > browser is still on your page.
    > > > > >
    > > > > > You can add code to your page's client onunload event which could

    > > notify
    > > > > > your server that the page is unloading. This will not tell you if

    > the
    > > > > > browser is being closed.
    > > > > > For example: <body onunload="alert('closing');">
    > > > > >
    > > > > > If you use this method, use showModalDialog to browse to a page

    > which
    > > > > > notifies your server. That page will return JavaScript back to the
    > > > dialog
    > > > > > with window.close();.
    > > > > >
    > > > > > Another option is that you could write an ActiveX control.

    However,
    > > that
    > > > > > control will only exist so long as the user is on your page. You

    > still
    > > > > > won't know if they close the browser.
    > > > > >
    > > > > > Essentially, the internet was designed such that the server only

    > knows
    > > > > > about the browser while it is processing a request from the

    browser.
    > > The
    > > > > > rest of the time, the server is not aware of the browser.
    > > > > >
    > > > > > Does this answer your question?
    > > > > >
    > > > > > Thank you, Mike
    > > > > > Microsoft, ASP.NET Support Professional
    > > > > >
    > > > > > Microsoft highly recommends to all of our customers that they

    visit
    > > the
    > > > > > http://www.microsoft.com/protect site and perform the three
    > > > > straightforward
    > > > > > steps listed to improve your computer's security.
    > > > > >
    > > > > > This posting is provided "AS IS", with no warranties, and confers

    no
    > > > > rights.
    > > > > >
    > > > > >
    > > > > > --------------------
    > > > > > > From: "hb" <>
    > > > > > > Subject: Help: How to detect if the browser is closed?
    > > > > > > Date: Mon, 17 Nov 2003 09:09:01 -0500
    > > > > > > Lines: 11
    > > > > > > X-Priority: 3
    > > > > > > X-MSMail-Priority: Normal
    > > > > > > X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
    > > > > > > X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
    > > > > > > Message-ID: <>
    > > > > > > Newsgroups: microsoft.public.dotnet.framework.aspnet
    > > > > > > NNTP-Posting-Host: x403446fe.ip.e-nt.net 64.52.70.254
    > > > > > > Path:

    > cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
    > > > > > > Xref: cpmsftngxa06.phx.gbl
    > > > > microsoft.public.dotnet.framework.aspnet:191366
    > > > > > > X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    > > > > > >
    > > > > > > Hi,
    > > > > > >
    > > > > > > Would you please tell me how to detect if the client's browser

    is
    > > > > closed?
    > > > > > >
    > > > > > > I need such event to trigger a database modification.
    > > > > > >
    > > > > > > Thank you
    > > > > > >
    > > > > > > hb
    > > > > > >
    > > > > > >
    > > > > > >
    > > > > >
    > > > >
    > > > >
    > > > >
    > > >

    > >
    > >
    > >

    >
     
    hb, Nov 19, 2003
    #7
    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. NWx
    Replies:
    2
    Views:
    2,305
  2. Chris

    Detect if browser closed

    Chris, Apr 27, 2005, in forum: ASP .Net
    Replies:
    7
    Views:
    10,842
    Chris
    Apr 27, 2005
  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