簡體   English   中英

在瀏覽器中禁用后退按鈕不起作用

[英]Disable Back Button in browser Not working

以下代碼是包含計時器和其他2個功能的javascript

`
var sec; var min; var counter = setInterval(timer,1000); // 1000將每1秒運行一次

  //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);
}

`aspx.cs文件中的代碼

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

后退按鈕未禁用有人可以建議解決方案嗎?

該代碼不會禁用后退按鈕!

該代碼必須在前一頁上。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM