beansandsausages Posted December 10, 2008 Share Posted December 10, 2008 hi i have a query. i have a simple count down clock in javascript, counts down from 60min to 0min, but each time i leave the page and go back to it or refresh the page it starts from 60min again, how would i get it to remember the time and not start from 60min again? Sorry its not in java script topic, i couldnt decide it if was a java problem or ajax. Quote Link to comment https://forums.phpfreaks.com/topic/136351-count-down-clock/ Share on other sites More sharing options...
zq29 Posted December 10, 2008 Share Posted December 10, 2008 Cookies? Quote Link to comment https://forums.phpfreaks.com/topic/136351-count-down-clock/#findComment-711337 Share on other sites More sharing options...
beansandsausages Posted December 10, 2008 Author Share Posted December 10, 2008 Notice you moved the topic. Sorry where would i add the cookie to? this is the code: <div id="countdown"></div> <div id="notifier"></div> <script type="text/javascript"> Number.prototype.toMinutesAndSeconds = function() { var m = Math.floor(this / 60); var s = this % 60; return (m+":"+(s<10?"0":"")+s); } function _TDisplay() {} _TDisplay.prototype.init = function(seconds, output, notify) { this.tot = seconds; this.out = output; this.not = notify; this.ii = setInterval(this.tick, 1000); }; _TDisplay.prototype._tick = function() { this.out.innerHTML = (--this.tot).toMinutesAndSeconds(); if(!this.tot) { this.not.innerHTML = '<?php echo " hi "; ?>'; clearInterval(this.ii); } } TDisplay = new _TDisplay(); _TDisplay.prototype.tick = function() { TDisplay._tick.call(TDisplay); } //otherwise pre = (window.onload) ? window.onload : function () {}; window.onload = function () { pre(); TDisplay.init(3, document.getElementById('countdown'), document.getElementById('notifier')); } </script> Quote Link to comment https://forums.phpfreaks.com/topic/136351-count-down-clock/#findComment-711349 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.