Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
dear friends,


I have Question For U..

how to disable Back-Button in Browser while running applications using java script. and Does Not Page Refreshing or Reload.
While pressing Back Button.
????

By Mohan
Posted

We can disable the back navigation by adding following code in the webpage. Now the catch here is that you have to add this code in all the pages where you want to avoid user to get back from previous page. For example user follows the navigation page1 -> page2. And you want to stop user from page2 to go back to page1. In this case all following code in page1.


<script type="text/javascript">
    window.history.forward();
    function noBack() { window.history.forward(); }
</SCRIPT>
</HEAD>
<BODY onload="noBack();"
    onpageshow="if (event.persisted) noBack();" onunload=""></script>
 
Share this answer
 
Comments
Mohankumar.Engain 3-Nov-11 6:59am    
your answer is correct but page is reloaded.
I want without page reload while clicking back button in browser..

by mohan
arya1685 3-Nov-11 7:34am    
Try this one

<body önUnload="noBack()">
<script>
function noBack()
{
<span class="IL_AD" id="IL_AD1">window</span>.history.forward(1);
}
</script>

You can also use the below script, but i have noticed that it wont work in some browsers especially Mozilla v 3.5
view sourceprint?
if(history.length>0)
{
history.go(+1)
}
BobJanova 3-Nov-11 7:13am    
This doesn't disable back, it causes the page you go back to to immediately ask to go forward again. The user can probably stop that happening by pressing Escape to cancel the load.
Don't. Instead, make your site back-button (and open-in-new-tab etc, all the things that web users can easily do) tolerant. If you set your cache control headers and session state correctly, it shouldn't matter if users go back, they will either get a cached version (no server hit) if appropriate or a message telling them that the operation is no longer valid if that makes more sense.
 
Share this answer
 
Try this

HTML
<body onunload="javascript:history.go(1)">


Or see this

http://viralpatel.net/blogs/2009/11/disable-back-button-browser-javascript.html[^]

http://www.irt.org/script/311.htm[^]
 
Share this answer
 
v2
Comments
BobJanova 3-Nov-11 7:49am    
That doesn't work if the user uses a 'multi-back' dropdown like all modern browsers have (though it will make them not go to the page they thought which will annoy them).
dear friends,


I have Question For U..

how to disable Back-Button in Browser while running applications using mobile application . and Does Not Page Refreshing or Reload.
While pressing Back Button.
????
 
Share this answer
 
Comments
bbirajdar 3-Jan-12 8:49am    
I am not able to understand your term "Back-Button in Browser while running applications using mobile application". Do you want this functionality in a native mobile application or a mobile web application which runs inside a browser?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900