Reputation: 334
I am working on a website in which I want to close the browser window/tab when the Logout Successful page loads. I am doing this because after the Logout workflow if 'back' button is pressed on browser, it displays the previous page with all the confidential info visible. Since I cleared the session in the corresponding servlet, user cannot do anything after the logout but display of data is of quite concern.
For this pupose I am using below code (Logout.jsp)-
<body onload="self.close();">
<center>
You have been successfully logged out.<br>
</center>
</body>
The problem is that the above code is working fine on IE however, it is not working on Firefox and Chrome. I checked all the settings related to Java Script for Chrome and they are exactly the same as of my browser.
Alternatively, I tried to clear the history. For this purpose I used below code which I found on some website -
<body onload="window.history.forward(0)">
<center>
You have been successfully logged out.<br>
Kindly close the browser for security reasons.<br>
</center>
</body>
But this code is not working in any of the browser.
Any kind of help would be appreciated.
---------------- UPDATE ---------------
For the second option (i.e. clearing history), after much google and work, I was able to make it work. The solution is as below -
If a user follows the navigation page1 -> page2. And you want to stop user from page2 to go back to page1 then add below code on page1 -
<body onload="window.history.forward();">
//rest of the body
</body>
I tested it in IE and found it working perfectly.
Now, I am left with the original issue that why script is not working in Chrome.
Upvotes: 0
Views: 708
Reputation: 2610
Do not do that. Just verify if the session exists. If it doesn't ( since it logged off ) you send him automatically to login page. That way your site is hack proof because i can eliminate from firebug or any console the line where you just close my tab, and therefor i can still see the data.
Upvotes: 1