Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

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

irt.org | Knowledge Base | JavaScript | Redirect | Q1205 [ previous next ]

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

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?'


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.