How do I get JavaScript to delay, and then refresh the page

霸气de小男生 提交于 2019-12-06 04:13:50
function refreshPage() {
    //ensure reloading from server instead of cache
    location.reload(true);
}
function delayRefreshPage(mileSeconds) {
    window.setTimeout(refreshPage, mileSeconds);
}
var textfill = function () {
    var node = document.createElement("P");
    var x = document.getElementById('entertext').value;
    var textnode = document.createTextNode("The search results for: '" + x + "' will show up here");
    node.appendChild(textnode);
    document.getElementById("123").appendChild(node);
    delayRefreshPage(2000);
}

Summarizing @ioseph and my personal experience.

To do something after a certain amount of time use setTimeout - https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setTimeout

And to refresh the page, call

window.location.reload
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!