PDA

View Full Version : Help Needed.



Gloudo
01-26-2006, 12:33 PM
Is there a way to make a dynamic link menu that feeds itself with the content of a windows folder.

So when a file is added to the folder it automaticly appears in the link menu.

Who can answer/help me?:)

Twey
01-26-2006, 04:45 PM
Not in Javascript. Do you have any server-side languages?

Gloudo
01-26-2006, 08:04 PM
No, unfortunately not, its for a local intranet, running on a normal file server.

Twey
01-26-2006, 08:28 PM
'Fraid not, then. It may be possible with some advanced AJAX and a little server manipulation, but I wouldn't want to... oh wait.

<iframe style="width:0;height:0;display:none;" id="hiddenframe">Your browser does not support iframes, so the dynamic link menu will not be available.</iframe>
<script type="text/javascript">
window.onload = (function() {

var menuElement = document.getElementById("menu"); // Element to populate
var dir = "/downloads/"; // Directory to use. Must not have an index: it needs to send an "index of" page
var junkLinksTop = 0; // "Junk" links to cut off the top of the menu.
var junkLinksBottom = 0; // Same, for the bottom.

document.frames['hiddenframe'].src = dir;
menuElement.innerHTML = "";
var if = document.frames["hiddenframe"].document,
a = if.getElementsByTagName("a"),
i;
for(i=junkLinksTop;i<a.length-junkLinksBottom;i++) {
menuElement.innerHTML += '<a href="' + a[i].href + ">' + a[i].innerHTML + '</a>';
}
});
</script>This is horribly hacky, and untested, and I'm sure you'll need to tweak it, and it all hinges on your server producing "index of" pages for directories without indices.