Coding Thread, Html coding in Coding and Web Development; Is there any html code that people can kindly donate to me to refresh images in a html page? Not ...
-
12th November 2009, 11:10 AM #1 Html coding
Is there any html code that people can kindly donate to me to refresh images in a html page? Not sure if its possible, I have a meta tag to refresh the whole page but when you scroll down it takes you back to the top when it refreshs...
I think the only way to stop this is refresh the images within the page rather that the page but any other ideas welcomed....
Thank you in advance.
-
-
IDG Tech News
-
12th November 2009, 11:45 AM #2 
Originally Posted by
neon
I have a meta tag to refresh the whole page but when you scroll down it takes you back to the top when it refreshs...
You could set up a Javascript timer that changes the image. Give the image tag an ID that you can get Javascript to search for, then every time your timed function runs it simply goes an changes the "src" attribute of that image tag.
Edit: You might want to use a Javascript library such as JQuery to do the above, less messing around dealing with browser versions.
--
David Hicks
Last edited by dhicks; 12th November 2009 at 11:50 AM.
-
-
12th November 2009, 11:50 AM #3 Had a quick go with it but im not good enough at coding to know what to do....
<IMG src="imgname.jpg" width="320" height="240" border="1" name="refresh">
<SCRIPT language="JavaScript" type="text/javascript">
<!--
var t = 1 // interval in seconds
image = "imaginname.jpg" //name of the image
function Start() {
tmp = new Date();
tmp = "?"+tmp.getTime()
document.images["refresh"].src = image+tmp
setTimeout("Start()", t*1000)
}
Start();
// -->
</SCRIPT>
-
-
12th November 2009, 11:52 AM #4 
Originally Posted by
neon
Had a quick go with it but im not good enough at coding to know what to do...
That chunk of code looked about right, did you try running it, see what happened? You might want to make the timer interval a bit longer, certainly to start with, just so you get a chance to see what is happening. Also, won't you need a list of images in an array or something somewhere?
--
David Hicks
-
-
12th November 2009, 12:14 PM #5 tried running it but it did nothing, it had the picture in but did not update it... i am unsure about an array and where to put it?
-
-
12th November 2009, 12:27 PM #6 Close, but this might work (untested):
Code:
<IMG src="imgname.jpg" width="320" height="240" border="1" id="img">
<SCRIPT language="JavaScript" type="text/javascript">
<!--
var t = 1;
var image = "imaginname.jpg";
function Start() {
tmp = new Date();
tmp = "?"+tmp.getTime();
document.getElementById('img').src = image+tmp;
}
setInterval("Start()", t * 1000);
// -->
</SCRIPT>
-
Thanks to webman from:
mossj (15th November 2009)
-
12th November 2009, 01:27 PM #7 still no luck, displays the picture but does not refresh... any other ideas?
-
-
12th November 2009, 01:37 PM #8 I just put that on a page and it does seem to work - example here but with a different image loaded via the script to indicate that it has changed.
-
Thanks to webman from:
mossj (15th November 2009)
-
12th November 2009, 01:51 PM #9 hmmm... I can see it working on your link....
Have posted my script left my file locations in so you can see if i am doing anything wrong...
<IMG src="\\server\Adult Resources\xp11.jpg" width="320" height="240" border="1" id="img">
<SCRIPT language="JavaScript" type="text/javascript">
<!--
var t = 3;
var image = "\\server\Adult Resources\xp11.jpg";
function Start() {
tmp = new Date();
tmp = "?"+tmp.getTime();
document.getElementById('img').src = image+tmp;
}
setInterval("Start()", t * 1000);
// -->
</SCRIPT>
-
-
14th November 2009, 04:57 PM #10 Its refreshing to the same image, so you will not see anything change. You would need to put a different image name in where you have var image = "\\server\Adult Resources\xp11.jpg";
Steve

Originally Posted by
neon
hmmm... I can see it working on your link....
Have posted my script left my file locations in so you can see if i am doing anything wrong...
<IMG src="\\server\Adult Resources\xp11.jpg" width="320" height="240" border="1" id="img">
<SCRIPT language="JavaScript" type="text/javascript">
<!--
var t = 3;
var image = "\\server\Adult Resources\xp11.jpg";
function Start() {
tmp = new Date();
tmp = "?"+tmp.getTime();
document.getElementById('img').src = image+tmp;
}
setInterval("Start()", t * 1000);
// -->
</SCRIPT>
-
-
15th November 2009, 07:54 PM #11 
Originally Posted by
webman
I just put that on a page and it does seem to work -
example here but with a different image loaded via the script to indicate that it has changed.
Thanks for that webman, okay to use it in a commercial enviroment?
-
-
15th November 2009, 10:15 PM #12 the image xp11.jpeg is changing every second, it is a webcam output picture thjat changes every second, if I f5 the webpage the picture changes?
-
-
16th November 2009, 08:26 AM #13 I can't see anything wrong with the code whatsoever.
Make sure that the images url is different every time (check the properties).
It should be something like....
For Example:
xp11.jpg?1258360019056
then the number will be different on refresh:
xp11.jpg?1258360024056
Ensure it's actually different, if it IS, then the code is doing its refresh thang.
-
-
16th November 2009, 08:28 AM #14 
Originally Posted by
mossj
Thanks for that webman, okay to use it in a commercial enviroment?
Sure, although I just slightly modified the original post by neon.
@neon: Instead of using UNC paths, try using this:
Code:
file:///server/Adult Resources/xp11.jpg
-
-
16th November 2009, 10:54 AM #15 if i put in file:///server/Adult Resources/xp11.jpg it doesnt even display the picture in the webpage... ?
but if i put \\server\Adult Resources\xp11.jpg it works... just doesnt refresh
-
SHARE: 
Similar Threads
-
By garethedmondson in forum General Chat
Replies: 6
Last Post: 14th October 2009, 04:10 PM
-
By DaveP in forum How do you do....it?
Replies: 2
Last Post: 16th July 2008, 02:10 PM
-
By russdev in forum Web Development
Replies: 5
Last Post: 11th November 2006, 10:49 PM
-
By plexer in forum Coding
Replies: 4
Last Post: 24th June 2006, 07:55 PM
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules