Search code examples
javascriptdjangodjango-modelsdjango-templatesdjango-staticfiles

Redirect django url with javascript


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";

}

Solution

  • You can use this:

     window.location.href = "{% url'app:result' %}"