SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Evangelist
    Join Date
    Nov 2005
    Posts
    496
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Is there an event listener or a property for close button/refresh?

    Hello...

    Is there an event listener or some kind of other way of finding out if a user has clicked the window close button on the browser or the refresh function of the browser?

    I know about onunload and onbeforeunload, but I wondered if there is some kind of event listener that checks for this kind of thing?

    Thanks! James

  2. #2
    SitePoint Wizard chris_fuel's Avatar
    Join Date
    May 2006
    Location
    Ventura, CA
    Posts
    2,750
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I really don't recommend attempting this. There's so much a user can do to prevent your script from launching under the mentioned conditions that it can't be guaranteed to work all the time.

  3. #3
    SitePoint Evangelist
    Join Date
    Oct 2005
    Location
    Michigan, USA
    Posts
    434
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    As far as I know, that doesn't exist. But if you wanted to check for people leaving your site, have an onbeforeunload check a variable for a certain value.

    For example, initialize a javascript var good=0 let's say, then all of your "valid" links on each page need to set good to 1. If good is zero when they leave, they didn't use one of your links to leave the page.

  4. #4
    SitePoint Member
    Join Date
    Dec 2005
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i dont believe there is anything you can do with the window close, cause thats is a functional broweser action (i.e. not just leaving the site, but exiting program). But for the refresh, you could set a cookie that is set when the user first visits the site and if they refresh the page you could check against that.


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
  •