SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2009
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Fire JS Function on browser kill

    I want to fire a JS Function when the user kills the browser close button.

    Can anyone suggest a solution that runs across all the browsers.

  2. #2
    SitePoint Zealot
    Join Date
    Jun 2009
    Location
    Ottawa, Ontario, Canada
    Posts
    120
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I could be mistaken but I believe that javascript does not have the ability to manipulate the chrome of the browser. It can read a scroll position and window size but I've never heard of executing a script when a window is being closed.

    floater

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2008
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In jQuery you can bind the event unload to any document element. It will fire when you leave the page or kill the browser and it's pretty consistent in every browser.

    The javascript equivalent is onunload.

    A side note: if you make an ajax-call on the unload-event, then you have to make it synchronous to be able to execute (default is async).
    b-change.nl - University student organization


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •