Click here to Skip to main content
15,885,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to disable back button on firefox using javascript
Posted
Updated 28-Aug-12 2:00am
v2
Comments
Legor 28-Aug-12 8:00am    
You really shouldn't do that. It's a bad habit of restricting users like that and they will not approve it.
Arunprasath Natarajan 28-Aug-12 23:59pm    
He might require for any Exam, Payment related pages i guess. So he does not want his user to perform such action.

 
Share this answer
 
Dear Friend,

Identify the Back Keys, key event and disable the same.
Here I have give a sample code to display the F5 key.

C#
document.onkeydown = function(e) {
      // keycode for F5 function
      if (e.keyCode === 116) {
        return false;
      }
      // keycode for backspace
      if (e.keyCode === 8) {
        // try to cancel the backspace
        return false;
      }
    };


If you want to hide the back button from the browser, then you can hide toolbar by calling the child window.
EG:
newwindow=window.open(url,'','toolbar=no,location=no,menubar=no,scrollbars=yes');
 
Share this answer
 
v2
Comments
Legor 28-Aug-12 8:02am    
Although this may work with the Backspace key i guess the OP wanted to disable the Button in the Browser GUI (the Left-Arrow) for going back one page. Eitherway i wouldn't suggest anyone restricting an user to do that.
Arunprasath Natarajan 28-Aug-12 10:15am    
Refer the above edited answer.
SharmilaB 16-Mar-13 6:32am    
this is working in internet explorer,but not in firefox
hiii,


XML
<SCRIPT type="text/javascript">
    window.history.forward();
    function disableBack()
{
window.history.forward();
}
</SCRIPT>
</HEAD>
<BODY onload="disableBack();" onpageshow="if(event.persisted) disableBack();">
 
Share this answer
 
$(window).unload(function () {
if (document.getElementById("status").value == "1") {

window.location = "Homepage.aspx";
return true;
}
else {

window.location = "LoginPage.aspx";
return true;
}
});
function Login_Click1() {
document.getElementById("status").value = "1";
}




Take one hidden field like loading status as 0 like below:

 
Share this answer
 
JavaScript
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<title>Untitled Page</title>
<script type = "text/javascript" >
function changeHashOnLoad() {
     window.location.href += "#";
     setTimeout("changeHashAgain()", "50"); 
}

function changeHashAgain() {
  window.location.href += "1";
}

var storedHash = window.location.hash;
window.setInterval(function () {
    if (window.location.hash != storedHash) {
         window.location.hash = storedHash;
    }
}, 50);
</script>

HTML
</head>
<body onload="changeHashOnLoad(); ">
Try to hit back!
</body>
</html
 
Share this answer
 
Comments
[no name] 29-Aug-12 4:44am    
continuously click on back button it will redirect to previous page...!(firefox)
Saroj Chaurasia 27-Aug-13 21:00pm    
Thank you very much!!! it saved my day...
SharmilaB 16-Mar-13 6:37am    
Thank you.....the above coding is working in html as well firefox!!!!!!!
prashant patil 4987 28-Aug-13 6:03am    
Welcome... please Vote me up..
prashant patil 4987 28-Aug-13 6:02am    
welcome Sharmila..

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