Clear Browser History using Javascript
If you need to clear the Browser History, after arriving on a particular page (e.g. arriving to Login page after Logout), below is the wicked way. This script needs to put in only on one page, from where you do not want to move back.
Second, if you do not want the user to move to the back page, you can do as below. This script needs to be repeated at every page.
Clearing browser history was eating my head. After the user clicks the logout from the portal and clicks on the back button from the browser, it get back the previous page. Finally I did it by the below steps, which I found to be interesting.
Step 1. Add the below javascript code on the page load
<script>
function callme()
{
history.go(1);
}
</script>
Step 2. Dont allow the page to be saved in cache. Add the below lines between <head>
<meta http-equiv="Expires" CONTENT="0">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="Pragma" CONTENT="no-cache">
Step 3. On click of Logout. Clear the history from the browser and redirects to Login page from server side.
string strScript = "<script>var Backlen=history.length;history.go(- Backlen);window.location.replace('Login.aspx');</script>";
ClientScript.RegisterClientScriptBlock(this.GetType(), "ClearHistory", strScript);
Trending Tutorials