0

hi

Iam using following script for time count, my Quiz project

<script type="text/javascript">
    var javascript_countdown = function () {
        var time_left = 10; //number of seconds for countdown
        var keep_counting = 1;

        function countdown() {
            if(time_left < 2) {
                keep_counting = 0;
            }
            time_left = time_left - 1;
        }
        function add_leading_zero( n ) {
            if(n.toString().length < 2) {
                return '0' + n;
            } else {
                return n;
            }
        }
        function format_output() {
            var hours, minutes, seconds;
            seconds = time_left % 60;
            minutes = Math.floor(time_left / 60) % 60;
            hours = Math.floor(time_left / 3600);
            seconds = add_leading_zero( seconds );
            minutes = add_leading_zero( minutes );
            hours = add_leading_zero( hours );
            return hours + ':' + minutes + ':' + seconds;
        }
        function show_time_left() {
            document.getElementById('javascript_countdown_time').innerHTML = format_output();//time_left;
        }
        function no_time_left() {
            document.getElementById('javascript_countdown_time').innerHTML = no_time_left_message;
        }
        return {
            count: function () {
                countdown();
                show_time_left();
            },
            timer: function () {
                javascript_countdown.count();
                if(keep_counting) {
                    setTimeout("javascript_countdown.timer();", 1000);
                } else {
                    no_time_left();
                }
            },
            init: function (n) {
                time_left = n;
                javascript_countdown.timer();
            }
        };
    }();
    javascript_countdown.init(20);
</script>

problem is counter is decreased by 20 seconds, I reload the page counter reset to 20 seconds.. how to solve this problem..

I want to whether page reload or not the counter can't reset to 20 seconds......

thanks in advance..

Edited by Nick Evan: Fixed formatting

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by cskinittest
0

You can refresh the page by using meta tag

<meta http-equiv="refresh" content="5; url=home.html">

This will refresh the current page after 5 seconds and will load home.html

0

You can refresh the page by using meta tag

<meta http-equiv="refresh" content="5; url=home.html">

This will refresh the current page after 5 seconds and will load home.html

thanks reply

i don't want to refresh the counter?

Edited by cskinittest: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.