Da du skal have fat i filsystem objektet, skal du bruge en browserinstans med specielle tilladelser. Skriv denne kode i et alm. dokument og kald den '
et_eller_andet.hta':
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "
http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<hta:application
ID="oHTA"
APPLICATIONNAME="myApp"
VERSION="1.0"
BORDER="thin"
BORDERSTYLE="normal"
CAPTION="yes"
ICON=""
MAXIMIZEBUTTON="yes"
MINIMIZEBUTTON="yes"
SHOWINTASKBAR="yes"
SINGLEINSTANCE="yes"
SYSMENU="yes"
WINDOWSTATE="normal"></hta:application>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="MSThemeCompatible" content="yes">
<meta http-equiv="X-UA-Compatible" content="IE=9">
<title>MyApplication</title>
</head>
<body>
<script type="text/jscript">
function readTextFile(sPath) {
var oFso = new ActiveXObject("Scripting.FileSystemObject"),
oFile = oFso.openTextFile(sPath, 1),
sContent = oFile.readAll();
oFile.close();
oFso = oFile = null;
return sContent;
}
function foo() {
var sCont = readTextFile("test.txt");
alert(sCont);
}
</script>
<p>
<button onclick="foo()">Læs fil</button>
</p>
</body>
</html>
Du kan læse mere om
HTA (HyperText Application)
her