Page 1 of 1
help.. I need a image loader that only loads image X times
Posted: Thu 12 Mar 2015 9:40 am
by ace2
I have 3 pages that currently have a image refresher every X seconds.
I need to be able to restrict how many times they load, say load every 20 seconds for a total of 10 minutes.
My 3 pages are :
http://ace2weather.com/index.htm
http://ace2weather.com/highlights.htm
http://ace2weather.com/cam.htm
Wondering if the GODS of code can help.....please....
Re: help.. I need a image loader that only loads image X tim
Posted: Thu 12 Mar 2015 11:50 am
by beteljuice
Modifying your code try something like:
Code: Select all
<script type="text/javascript">
picCount = 0;
picCountMax = ????; // Number of time to refresh
refreshInit = function()
{
picTimer = setInterval(refreshImage, 1*3000);
}
refreshImage function()
{
picCount++;
if(picCount <= picCountMax){
img = document.getElementById("icam");
img.src="http://ace2weather.com/snapshot.jpg?rand=" + Math.random();
} else {
clearInterval(picTimer);
}
}
</script>
</head>
<body onload="window.setInterval(refreshImage, 1*3000);">
Re: help.. I need a image loader that only loads image X tim
Posted: Thu 12 Mar 2015 12:16 pm
by ace2
beteljuice wrote:Modifying your code try something like:
Code: Select all
<script type="text/javascript">
picCount = 0;
picCountMax = ????; // Number of time to refresh
refreshInit = function()
{
picTimer = setInterval(refreshImage, 1*3000);
}
refreshImage function()
{
picCount++;
if(picCount <= picCountMax){
img = document.getElementById("icam");
img.src="http://ace2weather.com/snapshot.jpg?rand=" + Math.random();
} else {
clearInterval(picTimer);
}
}
</script>
</head>
<body onload="window.setInterval(refreshImage, 1*3000);">
That looks great, how would I use this with multiple images on one page like my highlights page, which you helped me with last time(you're a star)
I would even be happy with a load images on open only!!!
Re: help.. I need a image loader that only loads image X tim
Posted: Thu 12 Mar 2015 2:51 pm
by ace2
I choose a slightly different method for my index and cam page, I just added a
on the tail of the image source which seems to work, but i can't work out my highlight one as i have 6 images with 6 link that require random style reload
which uses
Code: Select all
<script type="text/javascript">
refreshImage = function()
{
img = document.getElementById("im1");
img.src="7am.jpg?rand=" + Math.random();
link = document.getElementById("lnk1");
link.href = "7am.jpg?rand=" + Math.random();
img = document.getElementById("im2");
img.src="9am.jpg?rand=" + Math.random();
link = document.getElementById("lnk2");
link.href = "9am.jpg?rand=" + Math.random();
img = document.getElementById("im3");
img.src="11am.jpg?rand=" + Math.random();
link = document.getElementById("lnk3");
link.href = "11am.jpg?rand=" + Math.random();
img = document.getElementById("im4");
img.src="2pm.jpg?rand=" + Math.random();
link = document.getElementById("lnk4");
link.href = "2pm.jpg?rand=" + Math.random();
img = document.getElementById("im5");
img.src="4pm.jpg?rand=" + Math.random();
link = document.getElementById("lnk5");
link.href = "4pm.jpg?rand=" + Math.random();
img = document.getElementById("im6");
img.src="6pm.jpg?rand=" + Math.random();
link = document.getElementById("lnk6");
link.href = "6pm.jpg?rand=" + Math.random();
}
</script>
</head>
<body onload="window.setInterval(refreshImage, 1*3000);">
But I can't figure out how to get it working with your script or even a the onload="loadImage()"
I would be happy to have it load on reload and have a refresh button.......
Re: help.. I need a image loader that only loads image X tim
Posted: Thu 12 Mar 2015 2:57 pm
by steve
Just put:
<body onload="refreshImage()">
Create a button to call the same function:
<button onclick="refreshImage()">Refresh images</button>
Re: help.. I need a image loader that only loads image X tim
Posted: Fri 13 Mar 2015 12:33 am
by ace2
Probably best to keep it simple and that seems to work fine....
Re: help.. I need a image loader that only loads image X tim
Posted: Fri 13 Mar 2015 8:31 am
by steve
...and your http bandwidth usage is now down to more reasonable levels

Re: help.. I need a image loader that only loads image X tim
Posted: Fri 13 Mar 2015 9:02 am
by ace2
steve wrote:...and your http bandwidth usage is now down to more reasonable levels

I kind of went into panic mode once informed.
Was editing/removing the rogue usage elements within the htm while at work using only a mobile phone.
