<script type="text/javascript"
language="javascript">
function DisableBackButton() {
window.history.forward()
}
DisableBackButton();
window.onload = DisableBackButton;
window.onpageshow = function(evt)
{ if (evt.persisted) DisableBackButton() }
window.onunload = function()
{ void (0) }
</script>
|
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Disable Browser Back buttons</title>
<script type="text/javascript"
language="javascript">
function DisableBackButton() {
window.history.forward()
}
DisableBackButton();
window.onload = DisableBackButton;
window.onpageshow = function(evt)
{ if (evt.persisted) DisableBackButton() }
window.onunload = function()
{ void (0) }
</script>
</head>
<body >
<form id="form1" runat="server">
<div>
First Page
</div>
<div>
<asp:Button id="btnFirst" runat="server" Text="Go to First Page" PostBackUrl="~/Default.aspx" />
<asp:Button ID="btnSecond" runat="server" Text="Go to Second Page" PostBackUrl="~/Default2.aspx" />
<asp:Button ID="btnThree" runat="server" Text="Go to Third Page" PostBackUrl="~/Default3.aspx" />
</div>
</form>
</body>
</html>
|
protected void Page_Init(object sender, EventArgs e)
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1));
Response.Cache.SetNoStore();
}
|
![]() |
|
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
Subscribe by RSS
Subscribe by Email
|
|||
|
|



Subscribe by RSS
Subscribe by Email
24 comments :
thnxx i was searching for it from days....................
i used the code but its not working
hi bhawna,
i tested it in all browsers it's working fine you should place that JavaScript function in all the pages wherever you need to disable back button
for master page and content page concept i want to disable back button on login page only which is one of the content page
hi bhawna,
you should place JavaScript code in login page of content placeholder and try it will work for you
thnn its working...
Hi Suresh This is sudheer trained .net developer.i am following ur portal daily and i am practicing most of the examples in ur blog, it is very useful to learn beginners.Can u post me Globalization/Localization concept with example please.
Its a good post for the beginners..:)
hi suresh,
This example works very well athe pages
Please help me to explain that how we count the user online and when i close the the browse the user count actually that the total user online please help with example
while clicking the back button it is showing the previous page for a glimpse...is it possible to remove it so it doesnt show the previous page and only stays on that page....????
actually i am talking about the thing that happens in gmail..after logging out it doest show me the login page for a glimpse
sory for my bad english....thanx in advance :)
actually i want the code for logout that exactly happens in gmail or in other websites...
plz help me...i need it
thank u :)
Hi sir..my requirment is i hav one form with 2 textboxes and submit button...i fill textboxes with values and submit means it ll save in database..the next time if i click the textbox to enter another record..the prevoiusly eneterd Value should not be dislayed..means all history content needs to be cleared..
can i use this code in html document having javascript????
Please Sir ,
give me Video Chat Code
this is useful and java script working but C# not working ...
thanks
Praveen Kumar S
thanks
Good one
It worked well , but you forced previous page to forward to current page , what if previous page is from another server? or what if i have only one page that is default.aspx . I mean how can i achieve the same thing when i face the situations i mentioned above ..
Thanks in advance
Cheers
awesome example ... good and keep it up.
hey...
i want to know how to give hyperlink to the gridview column through c# code... plx help me out
thanx bro
Hi suresh i have tried the code you have given but still when we are clicking on the bowser back button it shows the previous page for a few micro second. plz provide the solution. Thanks a lot for the article...
Thanks your great post, my brother!