Solved

Reload multiple images with variable filenames using javascript

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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to combine and minify CSS and JS files 5 16
AWK - Blank file output zero bytes why? 18 23
asp Google Map 2 24
Do alert on select 6 13
It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
This article discusses how to create an extensible mechanism for linked drop downs.
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
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.

808 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