neon Posted November 12, 2009 Posted November 12, 2009 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.
dhicks Posted November 12, 2009 Posted November 12, 2009 (edited) 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 Edited November 12, 2009 by dhicks
neon Posted November 12, 2009 Author Posted November 12, 2009 Had a quick go with it but im not good enough at coding to know what to do.... imgname.jpg
dhicks Posted November 12, 2009 Posted November 12, 2009 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
neon Posted November 12, 2009 Author Posted November 12, 2009 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?
webman Posted November 12, 2009 Posted November 12, 2009 Close, but this might work (untested): imgname.jpg <br /> <!-- <br /> var t = 1;<br /> var image = "imaginname.jpg";<br /> <br /> function Start() { <br /> tmp = new Date();<br /> tmp = "?"+tmp.getTime();<br /> document.getElementById('img').src = image+tmp;<br /> } <br /> <br /> setInterval("Start()", t * 1000);<br /> // --> <br /> 1
neon Posted November 12, 2009 Author Posted November 12, 2009 still no luck, displays the picture but does not refresh... any other ideas?
webman Posted November 12, 2009 Posted November 12, 2009 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. 1
neon Posted November 12, 2009 Author Posted November 12, 2009 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... \\server\Adult Resources\xp11.jpg
Devontechie Posted November 14, 2009 Posted November 14, 2009 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 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... \\server\Adult Resources\xp11.jpg
mossj Posted November 15, 2009 Posted November 15, 2009 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?
neon Posted November 15, 2009 Author Posted November 15, 2009 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?
Friez Posted November 16, 2009 Posted November 16, 2009 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.
webman Posted November 16, 2009 Posted November 16, 2009 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: file:///server/Adult Resources/xp11.jpg
neon Posted November 16, 2009 Author Posted November 16, 2009 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
webman Posted November 16, 2009 Posted November 16, 2009 (edited) 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 OK. Are you sure the picture itself is changing? If you change the initial img src to another (but leave the javascript reference the same), completely different picture, do you see it change? EDIT: Try this in the javascript part: var image = "\\\\server\\Adult Resources\\xp11.jpg"; Edited November 16, 2009 by webman
neon Posted November 16, 2009 Author Posted November 16, 2009 The image is definatly changing, I have it set up exactly as I want with the image at the top of the page refreshing (using metatag) however when you scroll down the page becasue it is refreshing the whole page it takes you back up to the top, thats why I only want to refresh the picture not the whole page... I will give the \\\\server a go and let you know.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now