Click here to Skip to main content
15,903,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Prevent user to move back page on pressing of back space key through java script.

I can try this but It should't work on Firefox browser but work on Google Crome browser.
I can use this code.

<script language="javascript" type="text/javascript">

function cancelBack()
{
if ((event.keyCode == 8 || (event.keyCode == 37 && event.altKey) || (event.keyCode == 39 && event.altKey))
&&
(event.srcElement.form == null || event.srcElement.isTextEdit == false)) {

event.cancelBubble = true;
event.returnValue = false;
}
}
</script>

and call this function like this.

<body onkeydown="return cancelBack();">
</body>

Please any one help me to solve this problem.

thanks in advance.
Posted
Updated 4-Feb-15 18:32pm
v3

You Can Use This Script

XML
<script type ="text/javascript">

    window.onload = window.history.forward(0);  //calling function on window onload

</script>
 
Share this answer
 
You shouldn't do it. Overriding the behaviour the user expects is not good user experience. if you have to, try using event.preventDefault();


You could return false as additional measure. The code below supports IE < 9. This assumes all your conditions in if clause are correct, I just copied them.

JavaScript
var event = e || window.event;
if ((event.keyCode == 8 || (event.keyCode == 37 && event.altKey) || (event.keyCode == 39 && event.altKey))
&&
(event.srcElement.form == null || event.srcElement.isTextEdit == false)) {

event.stopPropagation ? event.stopPropagation() : (event.cancelBubble=true);
}


If this helps please take time to accept the solution. Thank you.
 
Share this answer
 

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