How to capture browser closing event with Javascript

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • karthik juneni

    How to capture browser closing event with Javascript

    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.c lientX 0 && window.event.cl ientY < 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.screenL eft 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.
    {

  • Anthony Jones

    #2
    Re: How to capture browser closing event with Javascript


    "karthik juneni" <karthikjuneni@ gmail.comwrote in message
    news:1175216943 .007367.201290@ y66g2000hsf.goo glegroups.com.. .
    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.c lientX 0 && window.event.cl ientY < 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.screenL eft 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.


    Comment

    Working...