Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 469
  • Last Modified:

Java Slideshow Read Directory of Various Named Images?

I've seen many examples of Java slideshows that load hard-coded file names or number/name images (image1, image2, etc).

Q. How can I dump various named .jpg's in a folder and have a Jave slideshow loop through them?
0
pointeman
Asked:
pointeman
  • 4
  • 3
1 Solution
 
JoachimMartinsenCommented:
You could use a script like Lightbox:
http://www.lokeshdhakar.com/projects/lightbox2/
0
 
numberkruncherCommented:
For a range of images named:

image_1.jpg
image_2.jpg
image_3.jpg
image_4.jpg

You could use something like the following:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<title>Demo Page</title>
		<script language="javascript" type="text/javascript"> 
			var currentImageIndex = 0, count = 4;
 
			function imageChanger() {
				document.getElementById("imagePH").src = "image_" + (++currentImageIndex) + ".jpg";
				if (currentImageIndex >= count)
					currentImageIndex = 0;
			}
 
			window.onload = function() {
				imageChanger();
				setInterval(imageChanger, 1000);
			};
		</script>
	</head>
	<body>
		<h1>Demo Page</h1>
		<div>
			<img id="imagePH">
		</div>
	</body>
</html>

Open in new window

0
 
pointemanAuthor Commented:
Q. Java is client-side and cannot read server-side machine directories?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
pointemanAuthor Commented:
Here's an interesting directory file list array option:
var myloc = window.location.href;
var locarray = myloc.split("/");
delete locarray[(locarray.length-1)];
var arraytext = locarray.join("/");
 
0
 
numberkruncherCommented:
Yes, JavaScript is client-side; and you are right, it does not have access to server-side machine directories. But, that does not stop JavaScript from dynamically constructing paths to content which is stored on the server.

Remember that paths can be either absolute or relational. In the above example we are using relational paths. Relational paths are (by default) relative to the URI of the web page. However, this functionality can be manipulated using the <base> tag from within the <head> section of a HTML page.

The fact that a script generates the file name "image_1.jpg" (for example) and assigning that to the "src" attribute of an <img> is no different to the following:

<img src="image_1.jpg"/>
 
The only difference is that you are dynamically setting the "src" attribute:
 
document.getElementById('imagePH').src = 'image_1.jpg';
 
Both will load 'image_1.jpg' from the same directory as the page is stored in.

Open in new window

0
 
numberkruncherCommented:
I am not sure what you mean by the following:

> Here's an interesting directory file list array option:

> var myloc = window.location.href;
> var locarray = myloc.split("/");
> delete locarray[(locarray.length-1)];
> var arraytext = locarray.join("/");
0
 
pointemanAuthor Commented:
I'm not new to Javascript, but new to accessing server files as I can easily do with ASP.NET. I've been researching ActiveX / Javascript examples and I find its not a good cross-browser solution.
I'll use your code example and strictl name each uploaded file accordingly.
Thanx
0
 
numberkruncherCommented:
Provided that JavaScript is enabled (which is required for an automated slideshow) then all major web browsers support this.

The JavaScript is not actually accessing the server files; it is simply telling the DOM where to find the image.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now