views:

51

answers:

4

Apparently in IE8, there is this option 'Preserve Favorites website data', even if I uncheck it the browser will still keep the cookies until the last window is closed.

Problem scenario. say I logged in to somesite.com, then without logging out, I closed the window, but there was still another IE8 window open. In this case IE8 will keep the cookies of this site. So If I opened the site again (same window or another) the site won't ask for login info.

The client wants the web application to be logged off as soon as the user closes the browser. Can I force delete the cookies IE8 is saving? or maybe I can stop the user from closing the window until I simulate a click on logout button?

+1  A: 

Can you set a cookie with a negative expiration date in the onunload event of the browser?

Aaron Harun
A: 

this might help you.

Reigel
A: 

You can control existence of window through sending frefuent ajax requests. When client loads new page you should verify time of last checkup request.

Riateche
+1  A: 

Thanks all, I have tried many methods, including yours and didn't get it to work.

My solution was the following: When the user clicks the X button (browser close), a javascript onunload function will be called. This function simulates the clicking on logout button. The function pauses the browser until the logoff is executed.

Code:

window.onunload = function() {
    document.getElementById('logoutLink').click();
    windows.setTimeout(doNothingFunction,2000);
}

One side effect, is that this function will be actually called each time the user navigates out of the current page, not only on window close.
Solution, when navigating from page to page, a flag namely closingWindow is set to false. But when the user click the X button, the flag won't be set to false.

The new function to solve the side effect.

window.onunload = function() {
    if (closingWindow){
        document.getElementById('logoutLink').click();
        windows.setTimeout(doNothingFunction,2000);
    }
}
medopal