Recently in an application we developed there was a requirement to stop the browser back button after user logs out of the application.
The reason behind this was to stop the security risk of another user without proper permissions peeking into the earlier users screens. If you notice in many applications if the browser back is not properly handled then after the user is logged out you can re visit the site by just pressing the browser back button. This happens because the browser shows the cached page when the back is pressed. Even if you have server side code to check for the user they will not fire since the page will load from cache.
With the limited time I found a genius idea to handle this in the internet. What this javascript does is it will always try to put the user back to the last page in the history. For example, I am having a login page and a default page which I am taking a user after he logs in. You need to place the following javascript in the default page to make the above happen.
- <script type="text/javascript" language="JavaScript">
- window.history.forward(1);
- </script>
Then once a user logs out from the system and if presses the back button of the browser, when the default page loads it will put the user again to login (history forward) page which is the login page. Ultimately user needs to login again to go back to the site.
I have used the same code but when I click browser back button I am going to back pages, which should not be done.
I think you placed the code in the wrong page. For example think you have the page flow as below.
Login -> Default
If the user was in the Default page and logouts from the system he will end up in Login screen. If someone clicks browser back button then Default page will be shown, to stop this you need to put the above code in Default page. Then if the back button is pressed user will be aken forward meaning the user will end up in the Login screen.
With this I think you got a better understanding of using this, let me know if you need further help.
This code woks well for me. Thanks a lot.