窗口位置替换-超时帮助?Javascript问题 [英] Window location replace - timeout help? Javascript question
问题描述
我已经尝试过在重定向代码之前在代码中添加超时的方法.我已经在Google上搜索并找到了一些帮助,但是他们都没有按照我的预期进行操作
I have had tried to figure a way to add a timeout in my code before it redirects you. I have googled and found some help but none of them are doing what I expected
/****这会提示用户出生的年份并大致计算年龄*//*****如果未满18岁的使用者将他们带到迪斯尼乐园,否则不允许他们输入*/
/**** This prompts user what year they were born and calculates age (roughly) */ /*****If the user is under 18 takes them to Disneyland, if not they are allowed to enter */
function ageButton(){var askDOB =提示(你几岁?");
function ageButton() { var askDOB = prompt("What year were you born?");
if (askDOB > 2002) {
document.getElementById("agePass").innerHTML = "Access Denied"
window.location.replace("http://www.disney.com");
}
else {
document.getElementById("agePass").innerHTML = "Access Granted"
window.location.replace("http://www.w3schools.com");
}
}
仅需要一种方法即可在重定向之前暂停3秒钟
Just need a way to have a 3 second timeout before it redirects
推荐答案
您可以使用setTimeout(function,mss)来做到这一点.像这样的东西:
you can use setTimeout(function, milliseconds) to do that. something like this:
// location replace in 1 second
setTimeout(function(){
window.location.replace("http://www.disney.com");
}, 1000);
这篇关于窗口位置替换-超时帮助?Javascript问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!