I have encountered quite a few times when a page need to refresh itself or redirect to another page in a certain amount of time, and one of my friend also ask me this question before. So I think it would be good to put this code in an article so that it can be referenced later on very easily. The following javascript code can be used to redirect a page in 5 seconds. Copy and past them between script tags and change the (*Page URL*) as required.
var seconds = 5;

var milliseconds = seconds * 1000;

window.onload = function()
{
    // Call the function 5 seconds after the page is loaded.
    setTimeout("refresh_page()", milliseconds)
}


function refresh_page()
{
    window.location.href="http://(*Page URL*)";
    // Refresh after 5 seconds
    setTimeout("refresh_page()", milliseconds)
}

Leave a Reply

Your email address will not be published. Required fields are marked *