使用 javascript 重定向 django url

Swa*_*ker 2 javascript django django-templates django-models django-staticfiles

我有带有 javascript 的倒计时器,我想在倒计时结束后重定向到另一个页面。倒计时工作正常,但它没有重定向到结果页面

我试过这个:

应用程序.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";

}
Run Code Online (Sandbox Code Playgroud)

kam*_*yrb 5

你可以使用这个:

 window.location.href = "{% url'app:result' %}"
Run Code Online (Sandbox Code Playgroud)