Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Javascript Firefox
how to disable back button on firefox using javascript
Posted 28-Aug-12 2:54am
Edited 28-Aug-12 3:00am
Legor5.6K
v2
Comments
Legor at 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 at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Dear Friend,
 
Identify the Back Keys, key event and disable the same.
Here I have give a sample code to display the F5 key.
 
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');
  Permalink  
v2
Comments
Legor at 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 at 28-Aug-12 10:15am
   
Refer the above edited answer.
SharmilaB at 16-Mar-13 6:32am
   
this is working in internet explorer,but not in firefox
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

hiii,
 

<SCRIPT type="text/javascript">
    window.history.forward();
    function disableBack()
{
window.history.forward();
}
</SCRIPT>
</HEAD>
<BODY onload="disableBack();" onpageshow="if(event.persisted) disableBack();">
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

<script>
$(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";
}
</script>
 

 
Take one hidden field like loading status as 0 like below:
 
<input type="hidden" id="status" value="0" />
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

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>
</head>
<body onload="changeHashOnLoad(); ">
Try to hit back!
</body>
</html
  Permalink  
Comments
Karthik_J, Coimbatore at 29-Aug-12 4:44am
   
continuously click on back button it will redirect to previous page...!(firefox)
Saroj Chaurasia at 27-Aug-13 21:00pm
   
Thank you very much!!! it saved my day...
SharmilaB at 16-Mar-13 6:37am
   
Thank you.....the above coding is working in html as well firefox!!!!!!!
prashant patil 4987 at 28-Aug-13 6:03am
   
Welcome... please Vote me up..
prashant patil 4987 at 28-Aug-13 6:02am
   
welcome Sharmila..
prashant patil 4987 at 28-Aug-13 6:03am
   
.. please Vote me up.. if u like my answer..

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

  Print Answers RSS
0 Mathew Soji 330
1 BillWoodruff 260
2 Sergey Alexandrovich Kryukov 240
3 OriginalGriff 216
4 Afzaal Ahmad Zeeshan 208
0 OriginalGriff 6,168
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,028
3 Manas Bhardwaj 4,539
4 Maciej Los 3,845


Advertise | Privacy | Mobile
Web04 | 2.8.1411019.1 | Last Updated 29 Aug 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100