"Martin Kurz" <in**@martinkurz.in-berlin.de> wrote
Wade schrieb:
Is the a way to run through an unknown number of images with only
specifing the ending, like "run everything .jpg"?
Wade
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[i])
}
}
</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