admin管理员组文章数量:1406942
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";
}
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";
}
Share
Improve this question
asked May 21, 2020 at 8:07
Swapnil MangaonkerSwapnil Mangaonker
611 silver badge8 bronze badges
2 Answers
Reset to default 5You can use this:
window.location.href = "{% url'app:result' %}"
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
本文标签: Redirect django url with javascriptStack Overflow
版权声明:本文标题:Redirect django url with javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744941751a2633530.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论