Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. JavaScript
  4. countdown timer initializes on refreshing the page but it should not

countdown timer initializes on refreshing the page but it should not

Scheduled Pinned Locked Moved JavaScript
helpcsharpasp-net
4 Posts 2 Posters 4 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Amit Spadez
    wrote on last edited by
    #1

    Hello all, I have used the countdown timer in my asp.net project . It does working fine but the problem arises when I press f5 key or refresh in anyway..timer initialses again to maxmimum set time... So I need a solution for countdown timer that must not be affected on refreshing the page... Please help.......... thanks in advance Amit Jain

    D 1 Reply Last reply
    0
    • A Amit Spadez

      Hello all, I have used the countdown timer in my asp.net project . It does working fine but the problem arises when I press f5 key or refresh in anyway..timer initialses again to maxmimum set time... So I need a solution for countdown timer that must not be affected on refreshing the page... Please help.......... thanks in advance Amit Jain

      D Offline
      D Offline
      daveyerwin
      wrote on last edited by
      #2

      Well, one answer is 'use frameset with timer in a frame that doesn't get refreshed'.

      A 1 Reply Last reply
      0
      • D daveyerwin

        Well, one answer is 'use frameset with timer in a frame that doesn't get refreshed'.

        A Offline
        A Offline
        Amit Spadez
        wrote on last edited by
        #3

        Thanks for your reply bro.. But it doesn't work When I refresh the whole page ...frameset automatically refreshes and time again intialises to the given time (say 10 min) and starts counting down.. Any alternative to this ??

        D 1 Reply Last reply
        0
        • A Amit Spadez

          Thanks for your reply bro.. But it doesn't work When I refresh the whole page ...frameset automatically refreshes and time again intialises to the given time (say 10 min) and starts counting down.. Any alternative to this ??

          D Offline
          D Offline
          daveyerwin
          wrote on last edited by
          #4

          blockquote class="FQ">

          vinci007 wrote:

          Any alternative to this ?? Yes, store the start time in a cookie. here is a very simple example

          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

          <html xmlns="http://www.w3.org/1999/xhtml">

          <head>
          <title>My Timer Page</title>
          </head>
          <body>
          here is a timer that will keep count<br /> even if page is refreshed<br />press button to reset<br />
          <div id="timerDisplay"></div>
          <div><input type="button" onclick="myTimer.reSet()" /></div>
          </body>
          <script type="text/jscript">
          var myTimer = (function () {
          var readCookie = function () {
          var ca = document.cookie.split(';');
          for (var i = ca.length; i--; ) {
          var c = ca[i].split('name=');
          if (c.length == 2) return c[1];
          };
          return 0;
          };
          if (!readCookie()) {
          document.cookie = "name=" + (new Date().getTime()) + "; path=/";
          };
          var stuff = {};
          stuff.howLong = function () {
          return new Date().getTime() - readCookie()
          };
          stuff.reSet = function () {
          document.cookie = "name=" + (new Date().getTime()) + "; path=/";
          };
          return stuff;
          })();

          setInterval("document.getElementById('timerDisplay').innerHTML = myTimer.howLong();", 500);
          </script>
          

          </html>

          modified on Wednesday, August 25, 2010 9:45 PM

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups