Question:

How to find if the browser is being closed or refreshed ?

by  |  earlier

0 LIKES UnLike

I am working on a jsp project and I need to delete some data from the database automatically when the user closes the browser window(Like logging off).I cannot use onUnload as it triggers when the user does a refresh also.

To be more specific

When the user closes the window I need to execute a function which does the logging off activities.Any was to achieve this using AJAX (,Javascript) ?

 Tags:

   Report

3 ANSWERS


  1. <html>

    <head>

    <script>

    function doLogoff() {

    alert('send message to server');

    }

    window.onbeforeunload = doLogoff;

    </script>

    </head>

    <body>

    <p>

    content here

    </p>

    </body>

    </html>


  2. Close:

    http://www.w3schools.com/jsref/jsref_onu...

    Open/refresh:

    http://www.w3schools.com/jsref/jsref_onl...

  3. it maybe different for your browser but:

    you can go under tools and check the clear private data and make sure the options you want checked are checked...

    then go to edit -preferences and make sure that you have the option for it to automatically clear everything when the window is closed it will say something like always clear my private data when i close (your browser) and also make sure that you have the proper things chosen in the settings for that

Question Stats

Latest activity: earlier.
This question has 3 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.