0
votes

The following code is javascript containing a timer and other 2 functions

`
var sec; var min; var counter=setInterval(timer, 1000); //1000 will run it every 1 second

  //set the timer to the session variable only for the first time
 if(isPostBack == 'false'){
   sec=second;
   min=minute;  
 }

   //set the timer
   function timer()
 {

       if(isPostBack == 'true')
       {
          sec = second;
          min = minute; 
       }
       sec=sec-1;


     if(sec < 0)
    {
       sec=59;
       min--;
    }
    else
    {
      min=min;
    }

  if(sec <=9 )
  {
    sec = "0"+sec;
  }

  document.getElementById("lblCountDown").innerHTML= "Time Left: "+(min<=9 ? "0" + min : min)+"   mins"+" "+sec + " secs";

  //copy the value of min and sec in fields
  document.getElementById("min").value=min;
  document.getElementById("sec").value=sec;

 //copy the value of min and sec in session variable
  minute = min;
  second = sec;


  if (min <=0 && sec <= 0)
  {
     clearInterval(counter);
     alert("Times Up!!!. Your Test Will Be Auto Submited");
     document.getElementById("Submit").click();
     return;
  }          

}

function showKeyCode(e)
{

    var keycode =(window.event) ? event.keyCode : e.keyCode;

    if(keycode == 116)
    {
        alert("Page Cannot be refresh");
        event.keyCode = 0;
        event.returnValue = false;
        return false;
    }
}

function disableBackButton()
{
  window.history.forward(1);
}

` Code in aspx.cs file

`<body onload = "disableBackButton()" onkeydown = "showKeyCode()">

back button is not getting disable can anyone plz suggest the solution?

1
That code is not going to disable the back button! - epascarello
By the way, you should write === not == and I agree with @epascarello about disable button. - KrishnaDhungana
why this code will not disable the button? what is the proper way to do it? - user1852501
There is no proper way to "disable" a browser button, from a UX perspective you shouldn't be trying to take away an end users ability to use the browser as it was designed to work. - tremor

1 Answers

0
votes

That code is not going to disable the back button!

That code would have to be on the previous page.