PDA

View Full Version : Page refresh - number of times


GurusGuru
08-17-2002, 07:18 AM
How to modify the script so that after from refreshing after set time it should refresh for only x number of time. Say the page should reload after 300*1000 (time/seconds) for say 4 times (number). After the page has refresh 4 times, it should not refresh again.

<HTML>
<HEAD>
<script><!--
function doLoad()
{
setTimeout( "refresh()", 300*1000 );
}
function refresh()
{
window.location.reload( true );
}
//--></script>

</HEAD>

<BODY BGCOLOR=#FFFFFF onload="doLoad()">

beetle
08-17-2002, 09:01 AM
use a Cookie. Just add to the number stored till you hit four. there tons of examles out there for cookie writing, but, to get you started here's a link (http://www.javascripter.net/faq/index.htm)

joh6nn
08-18-2002, 09:46 PM
<script>
window.onload = function() {
if (!window.location.search) {
window.setTimeout("window.location += '?1';", 300000);
}
else {
var wieviel = Number(window.location.search.slice(1));
if (wieviel < 4 ) {
wieviel++;
window.setTimeout("window.location += '?'+wieviel;", 300000);
}
}
}
</script>

GurusGuru
08-19-2002, 11:05 AM
I am getting the following error:

An error has occured in the script on this page.

Line: 1
Char: 1
Error: 'wieviel' is undefined
Code: 0

joh6nn
08-19-2002, 07:55 PM
<script>
var wieviel;
window.onload = function() {
if (!window.location.search) {
window.setTimeout("window.location += '?1';", 300000);
}
else {
wieviel = Number(window.location.search.slice(1));
if (wieviel < 4 ) {
wieviel++;
window.setTimeout("window.location += '?'+wieviel;", 300000);
}
}
}
</script>

ok, try it now.

fitchic77
09-12-2002, 07:16 PM
I'm a newbie with javascript...can someone walk me through this a little bit..

Thanks,
Andrea

zipang
11-20-2011, 04:25 PM
I know this is a very old thread.
Please let me post this thread.

joh6nn did a great job.
But when I put this script, this shows like this.

index.html <= 1st time
index.html?1 <= 2nd time
index.html?1?2 <= 3rd time and stop

Is the 3rd one correct response?
I thought the 3rd one should be index.html?2
Please someone help me.
Thank you in advance.

Philip M
11-20-2011, 05:48 PM
I cannot make this work either. As Beetle said, use a cookie. Or try using the window.name method:-

<body onload = "getName()">

<script type="text/javascript">

function getName() {

var n = window.name;
if (!window.name) {window.name = 0}
alert ("Page reloaded " + window.name+ " times"); // for testing
n++;
if (n<5) {
window.name = n;
setTimeout("window.location.reload()",3000); // change 3000 to whatever value you want.
}

}

</script>