首页 > 解决方案 > 用javascript重定向django url

问题描述

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

我试过这个:

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

}

标签: javascriptdjangodjango-modelsdjango-templatesdjango-staticfiles

解决方案


你可以使用这个:

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

推荐阅读