Hi, im pulling this image from here: https://api.sat24.com/animated/EU/visual/2/GTB%20Standard%20Time/ and i
m using html plugin, its work but wont refresh image one is loaded, i need to refresh hole grafana page and then will update the image.
Little help how i can make it to work without refreshing hole grafana page?
You can write some JavaScript to refresh the image periodically. Itâs not related to Grafana really. See e.g. javascript - Refresh image with a new one at the same url - Stack Overflow
Hi Svet. I am a total klutz when it comes to HTML or Javascript. Most discussions of this ârefresh image with a new oneâ topic are ~10 years old, so obviously this is a well studied problem. I have tried as many ways as I can to get my image to refresh WITHOUT clicking the refresh button on the browser, but none have worked, so maybe you could help a brother out (even though this is the Grafana forum)âŚ
My URL loads perfectly via the Text panel in Grafana when I have just
<img src="http://192.168.10.140/Streaming/channels/101/picture"/>
but like the original poster here, my image (which is a still image from a video camera) does not refresh. Here is what I added:
<img src="http://192.168.10.140/Streaming/channels/101/picture"/>
<SCRIPT language="JavaScript" type="text/javascript">
var t = 20 // Interval in Seconds
image = "http://192.168.10.140/Streaming/channels/101/picture" //URL of the Image
function Start() {
tmp = new Date();
tmp = "?"+tmp.getTime()
document.images["refresh"].src = image+tmp
setTimeout("Start()", t*1000)
}
Start();
</SCRIPT>
and here is what I see:
Hm I think you have at least two issues:
- Your script isnât being picked up as such. I guess you havenât disabled the HTML sanitize option: Configuration | Grafana Labs. I would also recommend using lowercase HTML tags (e.g.
<script>
), though I donât think thatâs the issue here - You need to give your image and ID and then refer to that ID when triggering the refresh. See the snippet here: How to get the new image URL after refreshing the image using JavaScript ? - GeeksforGeeks
Thank you. Re: the second point, I will try something like this:
<!DOCTYPE html> <html> <head> <title>Refresh Image</title> </head> <body> <!-- Display the image --> <img id="gfgimage" src="bg.png" height="500" width="700" /> <script> // Create a timestamp var timestamp = new Date().getTime(); // Get the image element var image = document.getElementById("gfgimage"); // Adding the timestamp parameter to image src image.src = "bg.png?t=" + timestamp; console.log(image.src); </script> </body> </html>
Back againâŚDisabling the HTML sanitize made it better in that I no longer see the script text on the screen. But even after trying various coding ways to get the image URL to refresh (incl. using an ID), I still cannot get it to automatically refresh.
I am wondering if this whole disabling HTML sanitize got inadvertently broken in v8.1. I have read several past instances of scripts not working (even after setting the HTML sanitize option to TRUE), only to be fixed in another point release by Grafana. I am fairly confident that of all the various trials I have run, at least one had correct javascript code in there to automatically refresh the image. But it does not happen. Can someone running v8.1 say for sure that they are using the Text panel, set the Disable HTML sanitize to TRUE, and they are still running javascript code in the panel? Maybe show a snippet so I can try to duplicate it on my end?
I havenât tried JS in 8.1 but would be surprised if it has suddenly been disabled altogether (with the correct settings option).
Can you share your âbestâ attempt at the relevant JavaScript? Iâm afraid the one you shared in your last post doesnât actually do any refreshing, so I strongly suspect the issue is with the code. Checking your browserâs dev tools may offer some clues (e.g. JS errors). Have in mind that you shouldnât include any <html>
, <head>
, and <body>
tags - those already exist in the webpage. Only the stuff inside <body>
is what you should provide.
I can try to share a working example when Iâm back in front of my computer, but itâll be a few days (am currently on holiday)
Thanks for helping me during your holiday! Here is one that I found online that people said worked and which I could generally understandâŚ
<script language="javascript">
function updateImage() {
obj = document.imagename;
obj.src = obj.src + "?" + Math.random();
//Following statement sets the delay before the function will
//call itself again (in milliseconds)
setTimeout("updateImage()",5000);
}
//-->
</script>
<body onload="updateImage()">
<img src="http://192.168.10.144/Streaming/channels/101/picture" name="imagename">
</body>
Here is another attemptâŚ
Hi @grant2 Iâm afraid it looks like youâre stabbing in the dark here. A couple of points regarding the last few versions you shared:
- As I mentioned, your HTML should not include
<body>
tags; the Grafana web page already has a body and you canât nest another one inside it. - You should give the image an
id
(not aname
), and then use thatid
to refer to it in the JavaScript. The way to do that isdocument.getElementById(id)
. I donât think thatdocument.id
does anything useful. - You should make sure that the function you define actually gets called.
I havenât tested it myself, but I feel like something like the below might work:
<img src="http://192.168.10.144/Streaming/channels/101/picture" id="imageToUpdate" />
<script language="javascript">
function updateImage() {
image = document.getElementById("imageToUpdate");
image.src = "http://192.168.10.144/Streaming/channels/101/picture" + "?r=" + Math.random();
setTimeout(updateImage, 5000);
}
updateImage();
</script>
Maybe give it a go and see what happens? Be sure to check your browserâs JavaScript console (inside developer tools) for any errors. Good luck!
Thank you Svet! It works flawlessly. I have been working on getting this to work in some form or another for monthsâŚtried every plug in and now itâs finally working! I owe you a beer or coffee!
Ah, great to hear itâs working! Happy to help
Thank you for posting this! It doesnât seem to work for me though as the image does not refresh. Hereâs the code I am using. I have disable_sanitize_html set to true. Any ideas?
<img src="http://localhost:8000/my_picture.jpg" id="imageToUpdate" />
<script language="javascript">
function updateImage() {
image = document.getElementById("imageToUpdate");
image.src = "http://localhost:8000/my_picture.jpg" + "?r=" + Math.random();
setTimeout(updateImage, 2000);
}
updateImage();
</script>
HmmâŚnot sure. Maybe check your browserâs JavaScript console/log in dev tools? You could also add a debug message (like console.log("Refreshing")
) to the function, to check that itâs actually being run (again, by looking for that message in the browser log).
Thanks! I added the message to the code and the âRefreshingâ message showed in the console and yeah! the image now refreshes. I doubt that adding a message fixed it â I also decided to stop the docker, rebuild it and restart it so that is probably what fixed it. Thank you again for the solution!
This topic was automatically closed after 365 days. New replies are no longer allowed.