Welcome to the Cumulus Support forum.

Latest Cumulus MX V4 release 4.4.2 (build 4085) - 12 March 2025

Latest Cumulus MX V3 release 3.28.6 (build 3283) - 21 March 2024

Legacy Cumulus 1 release 1.9.4 (build 1099) - 28 November 2014
(a patch is available for 1.9.4 build 1099 that extends the date range of drop-down menus to 2030)

Download the Software (Cumulus MX / Cumulus 1 and other related items) from the Wiki

If you are posting a new Topic about an error or if you need help PLEASE read this first viewtopic.php?p=164080#p164080

reload a jpg that open in new window

Other discussion about creating web sites for Cumulus that doesn't have a specific subforum

Moderator: daj

Post Reply
User avatar
ace2
Posts: 679
Joined: Tue 14 Jan 2014 12:38 pm
Weather Station: maxkon ws-1081pc
Operating System: windows 7 & 8
Location: Adelaide, south Australia, Australia
Contact:

reload a jpg that open in new window

Post by ace2 »

I have a highlights page that refreshes the images every X seconds which works fine. These 6 stills are clickable which opens them in a new window, but i find the image is a cached version at times, what would be the best method making them reload completely once opened??

below is part of the main page refresh code i use, which is working great

Code: Select all

<script type="text/javascript">
refreshImage = function()
{
img = document.getElementById("im1");
img.src="7am.jpg?rand=" + Math.random();
</script>
And i add that into the page which refreshes fine.

Code: Select all

<a href="7am.jpg" target="_blank" ><img src="http://users.on.net/~ace2/7am.jpg" alt="7am.jpg" id="im1"></a><span style="color: #1A20CC">TAKEN AT 7AM</span>
But the clickable image sometimes loads a cached version instead of the refresh/reloaded version.
How could i fix this little issue, I know it's something really really simple!!!
Pages address is http://www.users.on.net/~ace2/highlights.htm if needed
CHRIS
Image
web site
http://www.ace2weather.com
Follow me on Twitter
http://tinyurl.com/kwlr9re
YouTube channel
http://tinyurl.com/lehwpgp
Facebook page
http://tinyurl.com/k3sap4s
Tiny URL links used
User avatar
rogerthn
Posts: 549
Joined: Thu 11 Apr 2013 6:31 pm
Weather Station: Ecowitt GW1000/GW1003
Operating System: Raspberry Pi OS bullseye aarch64
Location: Trollhättan Sweden
Contact:

Re: reload a jpg that open in new window

Post by rogerthn »

My php code to solve this issue

Function to get the timestamp of a file

Code: Select all

function timestamp($filename)
{
  if (file_exists($filename))
    return date ("YmdHis", filemtime($filename));
  else
    return "File $filename not found";
}
Add the timestamp to href

Code: Select all

$image_timestamp = timestamp("image.jpg");
print ("<div align=\"center\"><a href=\"image.jpg\"><img src=\"image.jpg[b]?$image_timestamp[/b]\" height=\"85%\" alt=\"Latest picture\" title=\"Latest picture\"></a></div>\n");
Addition of ?$image_timestamp to href does the trick for me
Image
User avatar
ace2
Posts: 679
Joined: Tue 14 Jan 2014 12:38 pm
Weather Station: maxkon ws-1081pc
Operating System: windows 7 & 8
Location: Adelaide, south Australia, Australia
Contact:

Re: reload a jpg that open in new window

Post by ace2 »

rogerthn wrote:My php code to solve this issue

Function to get the timestamp of a file

Code: Select all

function timestamp($filename)
{
  if (file_exists($filename))
    return date ("YmdHis", filemtime($filename));
  else
    return "File $filename not found";
}
Add the timestamp to href

Code: Select all

$image_timestamp = timestamp("image.jpg");
print ("<div align=\"center\"><a href=\"image.jpg\"><img src=\"image.jpg[b]?$image_timestamp[/b]\" height=\"85%\" alt=\"Latest picture\" title=\"Latest picture\"></a></div>\n");
Addition of ?$image_timestamp to href does the trick for me
Will php work with my HTML, my ISP doesn't allow/uee php according to there personal web space section...
CHRIS
Image
web site
http://www.ace2weather.com
Follow me on Twitter
http://tinyurl.com/kwlr9re
YouTube channel
http://tinyurl.com/lehwpgp
Facebook page
http://tinyurl.com/k3sap4s
Tiny URL links used
User avatar
rogerthn
Posts: 549
Joined: Thu 11 Apr 2013 6:31 pm
Weather Station: Ecowitt GW1000/GW1003
Operating System: Raspberry Pi OS bullseye aarch64
Location: Trollhättan Sweden
Contact:

Re: reload a jpg that open in new window

Post by rogerthn »

It should be possible to do something similar with javascript.
The line "img.src="7am.jpg?rand=" + Math.random();" in your refreshImage function does it.
Image
User avatar
mcrossley
Posts: 14388
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: reload a jpg that open in new window

Post by mcrossley »

Try...

Code: Select all

<script type="text/javascript">
refreshImage = function()
{
img = document.getElementById("im1");
img.src="7am.jpg?rand=" + Math.random();
link = document.getElementById("lnk1");
link.href = "7am.jpg?rand= + Math.random();
</script>

Code: Select all

<a id="lnk1" href="7am.jpg" target="_blank" ><img src="http://users.on.net/~ace2/7am.jpg" alt="7am.jpg" id="im1"></a><span style="color: #1A20CC">TAKEN AT 7AM</span>
User avatar
ace2
Posts: 679
Joined: Tue 14 Jan 2014 12:38 pm
Weather Station: maxkon ws-1081pc
Operating System: windows 7 & 8
Location: Adelaide, south Australia, Australia
Contact:

Re: reload a jpg that open in new window

Post by ace2 »

rogerthn wrote:It should be possible to do something similar with javascript.
The line "img.src="7am.jpg?rand=" + Math.random();" in your refreshImage function does it.
That line updates the page images, but not the link ones opening in a new window.
CHRIS
Image
web site
http://www.ace2weather.com
Follow me on Twitter
http://tinyurl.com/kwlr9re
YouTube channel
http://tinyurl.com/lehwpgp
Facebook page
http://tinyurl.com/k3sap4s
Tiny URL links used
User avatar
ace2
Posts: 679
Joined: Tue 14 Jan 2014 12:38 pm
Weather Station: maxkon ws-1081pc
Operating System: windows 7 & 8
Location: Adelaide, south Australia, Australia
Contact:

Re: reload a jpg that open in new window

Post by ace2 »

mcrossley wrote:Try...

Code: Select all

<script type="text/javascript">
refreshImage = function()
{
img = document.getElementById("im1");
img.src="7am.jpg?rand=" + Math.random();
link = document.getElementById("lnk1");
link.href = "7am.jpg?rand= + Math.random();
</script>

Code: Select all

<a id="lnk1" href="7am.jpg" target="_blank" ><img src="http://users.on.net/~ace2/7am.jpg" alt="7am.jpg" id="im1"></a><span style="color: #1A20CC">TAKEN AT 7AM</span>
Thanks, I'll give that a go
CHRIS
Image
web site
http://www.ace2weather.com
Follow me on Twitter
http://tinyurl.com/kwlr9re
YouTube channel
http://tinyurl.com/lehwpgp
Facebook page
http://tinyurl.com/k3sap4s
Tiny URL links used
User avatar
ace2
Posts: 679
Joined: Tue 14 Jan 2014 12:38 pm
Weather Station: maxkon ws-1081pc
Operating System: windows 7 & 8
Location: Adelaide, south Australia, Australia
Contact:

Re: reload a jpg that open in new window

Post by ace2 »

OK, that's all done, edited page on a nexus 4 phone, not an easy job I can tell you!!! :D
Now just need to test it.
Thanks mcrossley......
CHRIS
Image
web site
http://www.ace2weather.com
Follow me on Twitter
http://tinyurl.com/kwlr9re
YouTube channel
http://tinyurl.com/lehwpgp
Facebook page
http://tinyurl.com/k3sap4s
Tiny URL links used
User avatar
ace2
Posts: 679
Joined: Tue 14 Jan 2014 12:38 pm
Weather Station: maxkon ws-1081pc
Operating System: windows 7 & 8
Location: Adelaide, south Australia, Australia
Contact:

Re: reload a jpg that open in new window

Post by ace2 »

mcrossley wrote:Try...

Code: Select all

link.href = "7am.jpg?rand= + Math.random();
Works now after adding the missing " after rand=........
CHRIS
Image
web site
http://www.ace2weather.com
Follow me on Twitter
http://tinyurl.com/kwlr9re
YouTube channel
http://tinyurl.com/lehwpgp
Facebook page
http://tinyurl.com/k3sap4s
Tiny URL links used
User avatar
mcrossley
Posts: 14388
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: reload a jpg that open in new window

Post by mcrossley »

Ah yes, it was tryped on my phone.
User avatar
ace2
Posts: 679
Joined: Tue 14 Jan 2014 12:38 pm
Weather Station: maxkon ws-1081pc
Operating System: windows 7 & 8
Location: Adelaide, south Australia, Australia
Contact:

Re: reload a jpg that open in new window

Post by ace2 »

mcrossley wrote:Ah yes, it was tryped on my phone.

HEY, that's my excuse!!!
CHRIS
Image
web site
http://www.ace2weather.com
Follow me on Twitter
http://tinyurl.com/kwlr9re
YouTube channel
http://tinyurl.com/lehwpgp
Facebook page
http://tinyurl.com/k3sap4s
Tiny URL links used
Post Reply