Is there a way to prevent the countdown timer from resetting when refreshing data on an HTML page? I want to update the data without interfering with the countdown timer.
app.js
var count = 8
var counter = setInterval(timer , 1000)
function timer(){
count = count-1
if (count <= 0)
{
clearInterval(counter);
return window.location.href = urlFromDjango
}
document.getElementById("timer").innerHTML= count + " secs";
}
index.html
{% load static %}
<head>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
<link rel="stylesheet" href="{% static 'css/app.css' %}">
<script src="{% static 'js/app.js' %}"></script>
</head>
<script>
var urlFromDjango = "{% url 'app:result' %}"
</script>
<body>
<h1 id="timer"></h1>
</body>
<h1>{{user.username}}</h1><br>
<h2>score -{{user.userextend.score}}</h2>
<form action="{% url 'app:detail' quiz_id=que.quiz.id question_id=que.id %}" method="post">
{% csrf_token %}
{% for choice in que.answer_set.all %}
<input type="radio" name="choice" id="choice{{ forloop.counter }}" value="{{ choice.id }}">
<label for="choice{{ forloop.counter }}">{{ choice.answer }}</label><br>
{% endfor %}
<button><a href="{% url 'app:detail' %}">Next</a></button>
</form>