Dragosvr92 Posted August 13, 2013 Share Posted August 13, 2013 Hello, I am trying to add a reload button that when clicked, it will refresh/reload the images that have a "refresh" id... I'd also want the images to reload every 60 seconds. Does anyone have a script on hand..? i cant find one on the net. Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/281143-reload-image-button-and-every-60-seconds/ Share on other sites More sharing options...
Dragosvr92 Posted August 14, 2013 Author Share Posted August 14, 2013 I just tried this for the reload button but it doesnt seem to work and reload the image. <!DOCTYPE html> <html> <head> <script> function reloadPage() { document.getElementById("refresh").reload(); } </script> </head> <body> <input type="button" value="Reload page" onclick="reloadPage()"> <img id="refresh" src="img.png"> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/281143-reload-image-button-and-every-60-seconds/#findComment-1444917 Share on other sites More sharing options...
Irate Posted August 14, 2013 Share Posted August 14, 2013 If you want to use jQuery and have the image on your page, try using jQuery('input[type=button][value^=Reload]').click(function(){...}); To fetch the image, use jQuery().load() or any Ajax-method (GET, POST, whatever you like). Quote Link to comment https://forums.phpfreaks.com/topic/281143-reload-image-button-and-every-60-seconds/#findComment-1444947 Share on other sites More sharing options...
cyberRobot Posted August 15, 2013 Share Posted August 15, 2013 What are you looking to accomplish? Is the same image always being displayed...or are you looking to rotate through a series of different images? Quote Link to comment https://forums.phpfreaks.com/topic/281143-reload-image-button-and-every-60-seconds/#findComment-1445134 Share on other sites More sharing options...
nogray Posted August 15, 2013 Share Posted August 15, 2013 You need to change the image source (not reload) if you want to change it. Also, to avoid the image being cached, you need to add a random token in the url. e.g. <img id="refresh" src="img.png"> <script type="text/javascript"> // add this in an onload event or after the image setInterval(function(){ var src = 'img.png?rand='+(new Date().getTime()); document.getElementById('refresh').src = src; }, 60000); </script> Quote Link to comment https://forums.phpfreaks.com/topic/281143-reload-image-button-and-every-60-seconds/#findComment-1445218 Share on other sites More sharing options...
Dragosvr92 Posted August 16, 2013 Author Share Posted August 16, 2013 I have a page where i link dynamic images that show the status/data of a game server. Server name, number of players, map thats playing, etc. Im trying to reduce the server load without reloading the page everytime to reload an image. Cant i just reload a certain part of a page? Reload/refresh all contents inside a div? Quote Link to comment https://forums.phpfreaks.com/topic/281143-reload-image-button-and-every-60-seconds/#findComment-1445317 Share on other sites More sharing options...
cyberRobot Posted August 16, 2013 Share Posted August 16, 2013 Cant i just reload a certain part of a page? Reload/refresh all contents inside a div? Yep, try out nogray's code. Quote Link to comment https://forums.phpfreaks.com/topic/281143-reload-image-button-and-every-60-seconds/#findComment-1445334 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.