如何在浏览器或键盘后退按钮中单击后退按钮后传递Cookie

时间:2014-03-20 09:53:45

标签: javascript jquery cookies

我正在开发一个在线考试系统,在这个系统中,如果我将时间设置为10分钟,它将起作用。问题是我点击浏览器中的后退按钮,时间将重置

我正在使用cookie并在困惑后将时间存储在cookie中请帮忙

主要目标是点击后退按钮,时间将在cookie时间后重新加载。

 <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>

0 个答案:

没有答案