#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. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    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.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  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