Jump to content

Recommended Posts

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

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>

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).

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>

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.