Solved

Reload multiple images with variable filenames using javascript

Posted on 2007-03-23
4
389 Views
Last Modified: 2013-12-25
I have a perl cgi script that generates reports that may contain 1 to 100+ images. How can I reload the images (each with a filename generated using a datetime stamp) using javascript?

I'm a javascript newbie and I don't know how to deal with multiple images with variable filenames. How do I pass the filenames generated by the perl cgi script to a javascript function?

Thanks.
0
Comment
Question by:bespnmom
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 63

Expert Comment

by:Zvonko
ID: 18783536
If the majority of the images on the page has to be refreshed then I would recommand to refresh ALL images on the page.
Like this:

<script>
function reFresh(){
  var img = document.images;
  for(var i=0;i<img.length;i++){
    img.src = img.src.replace(/\?t\=\d+/g,"")+"?t="+(new Date()).getTime();
  }
}
</script>


0
 

Author Comment

by:bespnmom
ID: 18806725
I can't get it to work. What does this:
            img.src.replace(/\?t\=\d+/g,"")+"?t="+(new Date()).getTime();
do?
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 18807027
That statement generates the new src file name or url for the image so that it can be refreshed by new name.
That is done in upper statement in two steps:
1.) removing of previous time parameter from the image src String.
2.) adding of new time parameter to the src string.

0
 
LVL 63

Accepted Solution

by:
Zvonko earned 500 total points
ID: 18807041
Sorry, I missed the loop variable in the img Array.
Check better this:

<script>
function reFresh(){
  var img = document.images;
  for(var i=0;i<img.length;i++){
    img[i].src = img[i].src.replace(/\?t\=\d+/g,"")+"?t="+(new Date()).getTime();
  }
}
reFresh()
</script>


0

Featured Post

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show, step by step, how to integrate R code into a R Sweave document
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question