2

i have countdown timer with javascript, I want to redirect to another page after countdown is over.countdown works pefectly but it's not redirecting to the result page

i tried this:

app.js

var count = 15

var counter = setInterval(timer , 1000)

function timer(){
   count = count-1
   if (count <= 0)
   {
       clearInterval(counter);
       return window.location.replace("{% url'app:result' %}")
   }
   document.getElementById("timer").innerHTML= count + " secs";

}

2 Answers 2

5

You can use this:

 window.location.href = "{% url'app:result' %}"
Sign up to request clarification or add additional context in comments.

Comments

1

django template tags work inside the django templates. Since you have above javascript in the app.js file, this {% url'app:result' %} tag in the line below won't work because it is not valid javascript.

return window.location.replace("{% url'app:result' %}")

You can try moving the code from app.js into the corresponding django template and see if that works

1 Comment

Be aware that by using replace replaces the history's list last entry. This means that afterward, the back button will not go back to the original page. Assigning the URL to href creates a new entry in the history list

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.