|
|
Reading the contents of a directory
You are here: irt.org | Articles | JavaScript | Miscellaneous | Reading the contents of a directory Published on: Thursday 17th April 1997 By: Martin Webb This article will describe how it is possible to read the contents of a directory. there are, however, certain limitations:
Apart from these limitations, it has plenty of potential. The example I will demonstrate will use the following frame structure:
The test.htm document defines two frames:
The test.htm file loads a directory listing in the bottom directory frame (which in this example is the images directory on the irt.org we-site.) The browser will actually create hypertext links to the individual files, which can then be subsequently examined using the JavaScript links array. The reason this does not work in Internet Explorer, is that the browser does not create HTML hypertext links to the files. To ensure that the directory frame is completely loaded, we use the onLoad() event in the FRAMESET to load the main.htm document into the main frame. The contents of the main.htm file will then read the links array and will simply provide links to the files. This can then be easily adapted to display the data in any manner that you desire, e.g. tables, drop down menus, sorted by type, etc. The functionality of the main.htm can be enriched to provide, for example a picture browser, or a slide show. It removes the necessity to hardcode the contents of the directory within the JavaScript. The contents of the main.htm document is as follows:
The JavaScript finds the length of the links array. Which it then uses to walk through the links array outputing the href property within an anchor. Why not try out the example for yourself? Feedback on 'Reading the contents of a directory'
View the profile on Martin Webb and the list of other Articles by Martin Webb. |
-- div -->
|