Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think you can use cookies to store the current time and one flag=true before you switch to page 2; when you come back to page 1 you de-active flag=false to continue to calculate the time.</p> <p>you can do follow steps below:</p> <p>1) create a js file with content:</p> <pre><code>function setCookie(key, value, days) { var expires = ""; if (days) { var date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); expires = "; expires=" + date.toGMTString(); } document.cookie = key + "=" + value + expires + "; path=/"; } function getCookie(key) { var nameEQ = key + "="; var ca = document.cookie.split(';'); for ( var i = 0; i &lt; ca.length; i++) { var c = ca[i]; while (c.charAt(0) == ' ') c = c.substring(1, c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length); } return null; } function removeCookie(key) { setCookie(key, "", -1); } </code></pre> <p>2) At form 1 before click to go to form 2, you can set the current time to cookie.</p> <pre><code>setCookie("tracking_time", time_string, 5); </code></pre> <p>Please refer <a href="http://javascript.info/tutorial/datetime-functions" rel="nofollow">Javascript Date Time functions</a> to know how to get/set a time string</p> <p>3) when come back to form 1 from form 2, you can get time value from cookie , then you set to timer to continue count time.</p> <pre><code>var time_string = getCookie("tracking_time"); </code></pre> <p>Then you parse time_string to object </p> <hr> <p>This is a sample complete code</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;/head&gt; &lt;body&gt; &lt;span id="countdown"&gt;Start&lt;/span&gt; &lt;script&gt; function setCookie(key, value, days) { var expires = ""; if (days) { var date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); expires = "; expires=" + date.toGMTString(); } document.cookie = key + "=" + value + expires + "; path=/"; } function getCookie(key) { var nameEQ = key + "="; var ca = document.cookie.split(';'); for ( var i = 0; i &lt; ca.length; i++) { var c = ca[i]; while (c.charAt(0) == ' ') c = c.substring(1, c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length); } return null; } function removeCookie(key) { setCookie(key, "", -1); } var countdown = document.getElementById("countdown"); var days, hours, minutes, seconds; var target_date = getCookie("tracking_time"); if (target_date == null) { target_date = new Date().getTime() + (2*60*60*1000); // set countdown 2 hours } function updateTimer() { setInterval(function () { // this line below will set to function that user click on link to go to form 2 setCookie("tracking_time", target_date, 1); // End line // find the amount of "seconds" between now and target var current_date = new Date().getTime(); var seconds_left = (target_date - current_date) / 1000; // do some time calculations days = parseInt(seconds_left / 86400); seconds_left = seconds_left % 86400; hours = parseInt(seconds_left / 3600); seconds_left = seconds_left % 3600; minutes = parseInt(seconds_left / 60); seconds = parseInt(seconds_left % 60); // format countdown string + set tag value countdown.innerHTML = hours + "h: " + minutes + "m: " + seconds + "s"; }, 1000); } updateTimer(); &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload