The online exam countdown to prevent refresh based on Jquery+cookie implementation _jquery

Source: Internet
Author: User

Online Quiz Countdown to prevent refreshes based on Jquery+cookie

$ (function () {var _minute = parseint ("${exampaper.papertime}");
        
      var _expireshours = _minute * 60 * 1000;
      if (!hassetcookie ()) {Addcookie ("${examinee.examineeid}", _expireshours, _expireshours); 
    } settime ($ ("#remainTime"));
    });
      function Hassetcookie () {var strcookie = Document.cookie;
      var Arrcookie = Strcookie.split (";");
        for (var i = 0; i < arrcookie.length i++) {var arr = arrcookie[i].split ("=");
        if (arr[0] = = "${examinee.examineeid}") {return true;
      }
      };
    return false;
      //Start Countdown function SetTime (remaintime) {var _time = Getcookievalue ("871d31bacfd4451484c5f70f8860c2a9");
       
      var _countdown = parseint (Getcookievalue ("${examinee.examineeid}"))/1000; if (_countdown <= 0) {alert ("Time to test!")
        ");
      Endexam ();
        else {var _second = _countdown% 60; var _minute = parseint (_countdown/60)% 60;
        var _hour = parseint (parseint (_COUNTDOWN/60)/60);
        if (_hour <) _hour = "0" + _hour.tostring ();
        if (_second <) _second = "0" + _second.tostring ();
 
        if (_minute <) _minute = "0" + _minute.tostring ();
        remaintime.html (_hour + ":" + _minute + ":" + _second);
        _countdown--;
      Editcookie ("${examinee.examineeid}", _countdown * 1000, _countdown * 1000);
      settimeout (function () {settime (remaintime) is performed every 1000 milliseconds;
    }, 1000);
 
    }; Add Cookie function Addcookie (name, value, expireshours) {var cookiestring = name + "=" + escape (value);//esc
      The ape () function encodes the string so that it can be read on all computers.
        Determines whether the expiration time is set, 0 means that the invalidation if (expireshours > 0) {var date = new Date () is turned off by the browser.
        Date.settime (Date.gettime () + expireshours * 1000);
      cookiestring = cookiestring + "; expires=" + date.toutcstring (); } Document.cookie = CookiestRing //Modify the value of the cookie function Editcookie (name, value, expireshours) {var cookiestring = name + "=" + Escape (val
      UE);
        if (expireshours > 0) {var date = new Date (); Date.settime (Date.gettime () + expireshours * 1000);
      Unit is millisecond cookiestring = cookiestring + "; expires=" + date.togmtstring ();
    } document.cookie = cookiestring;
      The value function Getcookievalue (name) {var Strcookie = Document.cookie) that gets the cookie according to the name;
      var Arrcookie = Strcookie.split (";");
        for (var i = 0; i < arrcookie.length i++) {var arr = arrcookie[i].split ("=");
          if (arr[0] = = name) {return unescape (arr[1]);
        Break
        else {continue;
      };
    };
 }

The above is the entire contents of this article, I hope you can enjoy.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.