Joseph Zammit
Joseph Zammit

Reputation: 373

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

Upvotes: 0

Views: 251

Answers (2)

Nix
Nix

Reputation: 58522

I think what you are asking for is:

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

setTimeout(location.reload, closeTime);

But I don't understand why you care to close the div if you are just going to refresh the page.

If you want to close the div and refresh see @DontVoteMeDown's answer. My simply will reload the page after close time.

Upvotes: 0

DontVoteMeDown
DontVoteMeDown

Reputation: 21465

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);

Upvotes: 1

Related Questions