1

I have a requirment to disable the back button while login page come.

Noted below code is not working.

function DisableBackButton() {
    window.history.go();
}

window.onbeforeunload = DisableBackButton;

For serverside also i have added some serverside code as below.

response.setHeader("Cache-Control", "no-cache");
response.setHeader("Cache-Control", "no-store");
response.setHeader("Pragma", "no-cache");
response.setDateHeader("Expires", 0);%>
André Laszlo
  • 15,169
  • 3
  • 63
  • 81
SKC...
  • 223
  • 3
  • 7
  • 15

3 Answers3

0

This is a possible solution for HTML5:

<script type="text/javascript">
    location.hash='#no-';
    if(location.hash == '#no-') {
        location.hash='#_';
        window.onhashchange=function() {
            if(location.hash == '#no-')
                location.hash='#_';
        }
    }
</script>
Udo Klimaschewski
  • 5,150
  • 1
  • 28
  • 41
0

There are numerous reasons why disabling the back button will not really work. Your best bet is to warn the user:

window.onbeforeunload = function() { return "You work will be lost."; };

This page does list a number of ways you could try to disable the back button, but none are guaranteed

click this link

jmail
  • 5,944
  • 3
  • 21
  • 35
0

try this:

window.onload = function () { history.forward(); }; //force user to redirect
window.onunload = function() {}; // trick for some browsers like IE