Hello Reader's if you are developing the portal where you want to show user the coundown time. Then this blog is usefull to your. Let's see how to make an auto counter in Javascript:-
first create a html file and name it count.html and code will go like this:-
<!DOCTYPE html>
<html>
<body>
<p>Count numbers: <output id="result"></output></p>
<button onclick="StartMyCountdown()">Click to start times</button>
<button onclick="StopMyCountdown()">Click to stop</button>
</body>
</html>
Now the Javascript for the file will go like this:-
<script>
var start;
function StartMyCountdown() {
if(typeof(Worker) !== "undefined") {
if(typeof(start) == "undefined") {
w = new Worker("demo_workers.js");
}
w.onmessage = function(event) {
document.getElementById("result").innerHTML = event.data;
};
} else {
document.getElementById("result").innerHTML = "This browser is not supporting";
}
}
functionStopMyCountdown() {
start.terminate();
start = undefined;
}
</script>
Now on loading this page you will see a start button, when you click that button a timer will start showing the seconds which will start below it. And when user will click on stop timer the timer will stop at that time. This function can be used in online examination or booking services where you have to keep the timer events.
0 Comment(s)