直接搜索當前所有的HTML文件,並在div
標記中添加超鏈接.. 它的作品完美的IE ..但它不工作在Firefox和鍍鉻..任何人能幫助我....Firefox的問題列出當前目錄中的所有文件名
<script type="text/javascript">
function getCurrentDirectory() {
var fso = new ActiveXObject("Scripting.FileSystemObject");
path = unescape(document.location);
path = path.substring(8, path.lastIndexOf("/") + 1);
return path;
}
function ShowFolderFileList() {
var fso, f, f1, fc, s, temp, Extention, fileName, temp2, filePath;
folderspec = getCurrentDirectory();
fso = new ActiveXObject("Scripting.FileSystemObject");
f = fso.GetFolder(folderspec);
fc = new Enumerator(f.files);
s = "";
for (; !fc.atEnd(); fc.moveNext()) {
filePath = "" + fc.item() + "";
fileName = fc.item().name;
temp = "" + fileName + ""
Extention = (temp.lastIndexOf(".") > -1) ? temp.slice(temp.lastIndexOf(".") + 1).toLowerCase() : "*";
if (Extention == "html" || Extention == "htm") {
s += "<a href=\"" + fileName + "\" target=\"_blank\">" + temp.replace("." + Extention, "") + "</a> <br>";
}
}
outPut.innerHTML = s;
}
</script>
在HTML
<div id="outPut">
</div>
這個人工作....
ActiveXObject是僅在IE上可用的對象(其中一些可以在某些情況下工作,具體取決於用戶安全權限) – fcalderan 2012-07-25 10:57:35