Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q1205 How can I reload the same page automatically three times? And when using the refresh command, how can I get it to stop?

You are here: irt.org | FAQ | JavaScript | Redirect | Q1205 [ previous next ]

Using the meta tag like:

<meta http-equiv="refresh" content="10 ;url=index.html">

Will either continually reload the same page 10 seconds, or if used with different pages (e.g. index1.htm, index2.htm, index3.htm) will reload three times, but using three different pages.

The following JavaScript solution will give you what you want:

<html>
<head>
<script language="JavaScript"><!--
var Passed = '' + location.search;

if (Passed != '' && Passed != 'undefined')
    Passed = parseInt(Passed.substring(1));
else
    Passed = 3;

// This will go 3, 2, 1 and stay on 0....

function loopy() {
    loc = window.location.href
    sPos = loc.indexOf('?');
    if (sPos != -1) loc = loc.substring(0,sPos); // loose existing search
    window.location = loc + (Passed-1);
}
//--></script>
</head>

<body onLoad="setTimeout('loopy()',10000)">

<script language="JavaScript"><!--
document.write(Passed);
//--></script>

</body>
</html>

Feedback on 'Q1205 How can I reload the same page automatically three times? And when using the refresh command, how can I get it to stop?'

©2018 Martin Webb