Count down timer which don't reset on page refresh

痞子三分冷 提交于 2020-01-07 05:04:07

问题


How can I create a count down timer in JSF? I don't want the timer reset when refresh the page.


回答1:


You can simply use Java Script for it.

Or

You can use RichFaces a4j:poll and poll count data from server where your timer will be running




回答2:


You can use simply this script

 var seconds = readCookie('countdown') || 60;
        alert(seconds);
        function secondPassed()
        {
            seconds--;
            var minutes = parseInt(seconds / 60);
            var remainingSeconds = parseInt(seconds % 60);
            if (remainingSeconds < 10) {
                remainingSeconds = "0" + parseInt(remainingSeconds);
            }
            document.getElementById('countdown').innerHTML = minutes + " mins : " + remainingSeconds + " secs";
           if (parseInt(seconds) === 0)
            {
                alert("Time is over");
                clearInterval(countdownTimer);
                document.getElementById('countdown').innerHTML = "Time is Over";
                document.forms["myForm"].submit();
                document.location.href = "examresult.jsp";
            }
        }
        var countdownTimer = setInterval(function() {
            secondPassed();
            if (seconds === 0) {
                eraseCookie(seconds);
            } else {
                createCookie(seconds, seconds, 7);
            }
        }, 1000);


来源:https://stackoverflow.com/questions/4173598/count-down-timer-which-dont-reset-on-page-refresh

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!