Generally
there are cases when we want to disable back button in browser. We have multiple
options to disable back button in browser. Here are the few:-
Java Script Way
We can use following java script to prevent back button:-
Java Script Way
We can use following java script to prevent back button:-
<script
type = "text/javascript" >
function
disableBackButton()
{
window.history.forward();
}
setTimeout("disableBackButton()",
0);
window.onunload=function()
{
null
};
</script>
HTML Way
We can also add Meta Tags in Head Section like this:-
<meta
http-equiv="Pragma" content="no-cache" />
<meta
http-equiv="Expires" content="-1" />
If you want to do above approach through code. Here is the trick:-
HtmlMeta
refreshMetaTag = new
HtmlMeta();
refreshMetaTag.HttpEquiv
= "Refresh";
refreshMetaTag.Content
= "90";
Page.Header.Controls.Add(refreshMetaTag);
ASP.Net Way
In ASP.Net we can use Cache to disable back button like this:-
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now);