0

I am developing an online exam system, in this system if i set the time to 10 min it will work. The problem is i click on the back button in browser the time is going to reset

i am using cookie and storing the time in a cookie after i am confused please help out

Main goal is i click the back button the time will reload after the cookie time.

 <script type="text/javascript">
        var bool = true, bool1 = false;
        var sec =01;   // set the seconds
        var min =10;   // set the minutes
        var canno = 0;
        var dias = 0;
        var dc;


        function countDown() {

            sec--;

            if (sec == -01) {
                if (dc == !null) {
                    min = Math.floor(time / 60) - 1;
                    sec = time - min * 60;
                } else {

                    sec = 59;
                    min = min - 1;
                }
                }
                else {
                    min = min;
                }
                if (sec <= 9) { sec = "0" + sec; }
                time = (min <= 9 ? "0" + min : min) + " mins : " + sec + " sec ";
                if (document.getElementById) { document.getElementById('theTime').innerHTML = time };
                if (bool == true) {
                    start = window.setTimeout("countDown();", 1000);

            if (min == '00' && sec == '00') {
                alert("TimesUp! Moving to Next Page");

                var answer = document.getElementById('<%=txtEssay.ClientID%>').value;
                window.open("English_Skills.aspx?CandNo=<%=CandidateNumber%>&QuesNo=<%=QuesNo%>&a1=" + answer, "_self", "");

                sec = "00"; window.clearTimeout(SD);
            }
        }
        function setCookie(name, value, expires) {
            document.cookie = name + "=" + escape(value) + "; path=/" + ((expires == null) ? "" : "; expires=" + expires.toGMTString());
        }
        function getCookie(name) {
            var cname = name + "=";
            dc = document.cookie;

            if (dc.length > 0) {
                begin = dc.indexOf(cname);
                if (begin != -1) {
                    begin += cname.length;
                    end = dc.indexOf(";", begin);
                    if (end == -1) end = dc.length;
                    return unescape(dc.substring(begin, end));
                }
            }
            return null;
        }

        window.onload = countDown;

    </script>
     <script type = "text/javascript" >
         function preventBack() { window.history.forward(); }
         setTimeout("preventBack()", 0);
         window.onunload = function () { null };
         countDown();
          </script>
  • You could [try to detect your back button click](http://stackoverflow.com/questions/17594413/js-or-jquery-browser-back-button-click-detector) and then reset the cookie accordingly – Pete Mar 20 '14 at 10:08
  • Please change the code i not getting u comment pls – Pradeep Rao M Mar 20 '14 at 10:14

0 Answers0