Solved

Reload multiple images with variable filenames using javascript

Posted on 2007-03-23
4
378 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
  • 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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.
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

823 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