Changing Images: Question about obtaining image names

W

Wade

08242005 1416 GMT-5

Recently some of you helped me with a script to change images. Well I
was asked to make a change to the script and not knowing if what the
school system is even possible, Ill ask you all.

The script just loads some images and roates through them. However, the
school wants to be able to put more and more pictures in the folder and
the script pull all the images for rotation.

Ok, first I notice that all the images are pulled into an array. The
pictures that I have now are not uniformly named. Also, I do not know
from day to day if one will be added.

Is the a way to run through an unknown number of images with only
specifing the ending, like "run everything .jpg"?

Wade
 
A

alu

Martin Kurz said:
Wade schrieb:

Hi Wade,

well, it is possible - but not with client-side JavaScript. The images are
located in a directory on a webserver. The Script is running on a client
computer. The client doesn't know anything about files on the server without you
(or the server itself) telling him what files are lying there around (OK, the
client could try to load every possible string as filename).

So you have to insert the imagefiles to rotate on the site by any serverside
script (PHP, Perl, JSP or something like this) that reads the directorycontent
serverside and generates the filelist for the JS before submitting the page to
the client.

greetings,

Martin


Not exactly true. There is a way to do this client side, although it's a bit
tricky & may not work on some servers or on Safari (untested).
You can load the image directory url (which cannot contain an index.html
file) into an invisible iframe, then onload loop through the iframe's links
and check for ".jpg"
(this will not work with local files or cross-domain)
A quick test....

<iframe src="images/" name="imageDir" id="imageDir"
onload="imagesInIframe();" style="display:none"></iframe>

<sc ript type="text/javascript">

var imageFrame = self.frames['imageDir']

function imagesInIframe() {
for (var i = 0; i < imageFrame.document.links.length; i++) {
alert(imageFrame.document.links)
}
}

</sc ript>

Note the iframe onload attribute is only available in IE6 & Mozilla as far
as I know.
For more cross-browser compatibility you could check if the iframe has
loaded every few 100 milliseconds vs. using the onload attribute.
-alu
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,139
Latest member
JamaalCald
Top