Display alert when close the browser window

Discussion in 'JavaScript' started by ponnithya, Dec 23, 2009.

  1. #1
    Hi,
    I need to display alert when I close the browser window. Now I am using the following code to display the alert. But the alert is getting displayed even I click on any links. But the alert should not displayed when i click the link.

    If you have any solution, please let me know.

    Thanks in advance.


    This is my code:

    <HTML>

    <head>

    <script>

    function closeIt()

    {

    return "";

    }

    window.onbeforeunload = closeIt;

    </script>

    </head>

    <body>

    <a href="http://www.test.com">Click here to navigate to

    www.test.com</a>

    </body>

    </html>
     
    ponnithya, Dec 23, 2009 IP
  2. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #2
    I think this code works perfectly!!!
     
    s_ruben, Dec 23, 2009 IP
  3. ponnithya

    ponnithya Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thanks for reply ruban,

    This code works. But the alert is getting displayed even i click the link.

    But it should not displayed. Thats my requirement.
     
    ponnithya, Dec 24, 2009 IP
  4. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #4
    You want to get alert when it is clicked on "X"??
     
    s_ruben, Dec 24, 2009 IP
  5. ponnithya

    ponnithya Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    S. But the alert should not displayed when we click on any link.
     
    ponnithya, Dec 24, 2009 IP