#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    1
    Rep Power
    0

    Alert on Browser's close button click


    Hello
    I need to find browser close button click event in my web application. I need to show some alert message on that event. I tried to do it using window.onbeforeunload event, but it gets called on every page navigation or page refresh
    I need to execute that function only on close button click event
  2. #2
  3. Banned
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,938
    Rep Power
    0
    Hi,

    don't do it. When you annoy your users with stupid alert messages blocking their whole browser window, you'll prevent nobody from leaving your site, but many will never want to come back.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2010
    Location
    Manchester
    Posts
    10
    Rep Power
    0
    I think it depends on which browser the client is using. I use this for one of my sites...

    PHP Code:
    <body onbeforeunload="ConfirmClose()" onUnload="ConfirmClose();"

IMN logo majestic logo threadwatch logo seochat tools logo