Joseph Zammit Joseph Zammit - 2 months ago 9
Javascript Question

refresh on setTimeout

I have a javascript set timeout to close a div after 10 sec and I want to add a page refresh when the div is closed. The code I'm using is below.

<script>
var container_close_sec = "100";
var closeTime = container_close_sec * 100;

setTimeout("parent.close_div()", closeTime);

</script>


thanks

Answer

Try this:

var container_close_sec = 100;
var closeTime = container_close_sec * 100;

setTimeout(function() {
    parent.close_div(); // Closes div
    location.href = location.href; // Refresh page
}, closeTime);