How to capture browser closing event with Javascript

Discussion in 'ASP General' started by karthik juneni, Mar 30, 2007.

  1. Hi all,

    Iam trying to capture windows closing event (i.e) when the user clicks
    on the "X" button i want to capture that event and want to update some
    values in the database.I tried two methods but iam getting problems
    with the two methods.

    First,one i tried with

    function Unload()
    {
    if (window.event.clientX > 0 && window.event.clientY < 0)
    {
    //Browser closing
    }
    }

    But this method is called even when the user ic hitting the back
    button or refreshing the page.

    Second thing i tried was

    function Unload()
    {
    if (window.screenLeft > screen.width)
    {
    //Browser closing
    }
    else
    {
    //Browser refresh
    }
    }

    This works fine for browser refresh but this method is not called when
    the user closes the browser.

    Does any one know how to do this.

    Any urgent help will be appreciated.

    Thanks in advance.
    {
     
    karthik juneni, Mar 30, 2007
    #1
    1. Advertising

  2. "karthik juneni" <> wrote in message
    news:...
    > Hi all,
    >
    > Iam trying to capture windows closing event (i.e) when the user clicks
    > on the "X" button i want to capture that event and want to update some
    > values in the database.I tried two methods but iam getting problems
    > with the two methods.
    >
    > First,one i tried with
    >
    > function Unload()
    > {
    > if (window.event.clientX > 0 && window.event.clientY < 0)
    > {
    > //Browser closing
    > }
    > }
    >
    > But this method is called even when the user ic hitting the back
    > button or refreshing the page.
    >
    > Second thing i tried was
    >
    > function Unload()
    > {
    > if (window.screenLeft > screen.width)
    > {
    > //Browser closing
    > }
    > else
    > {
    > //Browser refresh
    > }
    > }
    >
    > This works fine for browser refresh but this method is not called when
    > the user closes the browser.
    >
    > Does any one know how to do this.
    >
    > Any urgent help will be appreciated.
    >
    > Thanks in advance.


    My advice is, forget it. Design the requirement out of the system. Anything
    that happens outside the client area of a browser belongs to the host system
    and is best left out of bounds of a web application.

    Any solution will be a kludge and apt to be broken by a later update to the
    browser.
     
    Anthony Jones, Mar 30, 2007
    #2
    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. Chirag Malvi
    Replies:
    1
    Views:
    1,891
    Jim Cheshire [MSFT]
    Nov 11, 2003
  2. Uma Muthu

    Capture the event of closing IE

    Uma Muthu, Nov 8, 2004, in forum: ASP .Net
    Replies:
    8
    Views:
    5,013
    prash
    Jun 18, 2007
  3. genc ymeri
    Replies:
    5
    Views:
    579
  4. =?Utf-8?B?Vk1J?=

    Closing popup window when closing parent window?

    =?Utf-8?B?Vk1J?=, Feb 14, 2007, in forum: ASP .Net
    Replies:
    3
    Views:
    666
    Thomas Hansen
    Feb 15, 2007
  5. Derek
    Replies:
    2
    Views:
    126
Loading...

Share This Page