?
Solved

Reload multiple images with variable filenames using javascript

Posted on 2007-03-23
4
Medium Priority
?
391 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 2000 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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 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…
Suggested Courses

777 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