I'm new to Javascript and want to write a script which will loop through the files in a folder and display them in a webpage. I've written the following which alternately displays two images in a folder, but I want to be able to add new files to that folder and have them added to this loop. I'm assuming I just need some code to populate the list of files in the folder, but don't know how to do that, nor how to make var have a variable max depending on the number of files. This will all be displayed locally, so there's no kind of web server. - <html>
-
-
<head>
-
-
<title>CMM Reference Part Check Compliance</Title>
-
-
<script type="text/javascript">
-
<!--
-
var image1=new Image()
-
image1.src="Slide1.gif"
-
var image2=new Image()
-
image2.src="Slide2.gif"
-
//-->
-
</script>
-
-
</head>
-
-
<body>
-
-
<img src="Slide1.gif" name="slide" width="95%" height="95%" />
-
-
<script>
-
<!--
-
//variable that will increment through the images
-
var step=1
-
-
function slideit() {
-
//if browser does not support the image object, exit.
-
if (!document.images)
-
return
-
document.images.slide.src=eval("image"+step+".src")
-
if (step<2)
-
step++
-
else
-
step=1
-
//call function "slideit()" every 10 seconds
-
setTimeout("slideit()",1000)
-
}
-
-
slideit()
-
//-->
-
</script>
-
-
</body>
-
-
</html>
How might I do this?
Thanks very much for your help
5 9407 Dormilich 8,658
Recognized Expert Moderator Expert
I don't think that javascript can read a directory, but if you name the files consistently you can request each of it with a loop.
Thats part of the issue, the names won't be consistent since they'll be related to all sorts of different things. What would I use instead then? PHP was mentioned somewhere but I know absolutely nothing about that.
Here,
put this code in images.php, and place the file in your images directory. -
<?php
-
header("Content-Type: text/javascript");
-
$AllowedExtensions = array(".gif", ".jpg", ".png", "jpeg");
-
echo "var images = new Array();";
-
$d = dir("./");
-
while (false !== ($entry = $d->read()))
-
{
-
if($entry != '.' && $entry != '..' && is_file($entry) && in_array(substr($entry,-4), $AllowedExtensions))
-
{
-
echo "images.push('{$entry}');";
-
}
-
}
-
$d->close();
-
?>
Then just call this file within <SCRIPT> -
<script type="text/javascript" src="images/images.php"></script>
Thanks very much, but how do I use that in the HTML? Where do I set the time delay between updating etc? (I'm new to all of this)
Dormilich 8,658
Recognized Expert Moderator Expert @Ca1icoJack
just call the script (as Canabeez posted) @Ca1icoJack
that's a question how you set the cache instructions. probably - // in images.php
-
header('Cache-Control: must-revalidate');
could suffice (more Cache-Control options). Cache instructions may also be set by the server.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: D Wright |
last post by:
It would suffice to state, I am very new to the .NET world, as well as
to Visual Studio, Visual C#, and ASP.NET. Nonetheless, I'm certain
the solution to several challenges I've presented myself...
|
by: Jameson |
last post by:
Happy New Year, Everyone!
I am trying to figure out how to display a bunch of images (mainly
JPEGs, but possibly a few GIFs and PNGs as well) that are stored in a
local directory on the system....
|
by: KitKat |
last post by:
Problem trying to figure this out, using a combo box selection I need to go
to each folder, Cam 1, Cam 2, Cam 4, Cam 6, Cam 7,and Cam 8 and display each
picture (from selection) from each folder...
|
by: mmalinsky |
last post by:
I have the following code that I borrowed from this NG to copy files
from one location to another:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles...
|
by: Mark Rae |
last post by:
Hi,
Just looking for some advice and/or recommendations here.
Scenario is corporate private intranet, ASP.NET 2 on Win2K3S, SQL Server
2005, WinXP + IE6 on all client desktops.
Client has a...
|
by: lord.zoltar |
last post by:
Hello,
I have a help file as a chm, which is added to the project as a
resource. I'm trying to display it as
System.Windows.Forms.Help.ShowHelp(Me, "Name_Of_Helpfile_Resource")
which obviously...
|
by: Lloyd Sheen |
last post by:
I have a list of JPG's which are found in a SQL Server database. When the
page selects a certain piece of data it will refer to the file system
(resident on IIS server with a virtual directory)...
|
by: =?Utf-8?B?UmljaA==?= |
last post by:
I removed a form and all its associated files (designer, vb, resx) from a
project because I was having a problem with that form. I copied these files
to another folder away from the project...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |