电脑技术学习

贴一段用javascript打开和保存本地文件的源码

dn001
<objectid="fileDialog"width="0px"height="0px"classid="clsid:F9043C85-F6F2-101A-A3C9-08002B2F49FB"codebase="http://activex.microsoft.com/controls/vb5/comdlg32.cab">
</object>
<textareaid=TxtBodystyle="background-color:#EEEEEE;width:100%;height:100">无标题</textarea>
<br>
<inputtype=buttonvalue=加载onclick="loadDoc()">
<inputtype=buttonvalue=保存onclick="saveDoc()">
<script>
functionloadDoc();
{;
fileDialog.CancelError=true
try{;
fileDialog.Filter="HTMFiles(*.htm)|*.htm|TextFiles(*.txt)|*.txt"
fileDialog.ShowOpen()
varfso=newActiveXObject("Scripting.FileSystemObject")
varreading=1
varf=fso.OpenTextFile(fileDialog.filename,reading)
//window.confirm(f)
varr=f.ReadAll()
f.close()
TxtBody.value=r
}catch(e){};
};
functionsaveDoc();
{;
fileDialog.CancelError=true
try{;
fileDialog.Filter="HTMFiles(*.htm)|*.htm|TextFiles(*.txt)|*.txt"
fileDialog.ShowSave()
varfso=newActiveXObject("Scripting.FileSystemObject")
varf=fso.CreateTextFile(fileDialog.filename,true)
f.write(TxtBody.value)
f.Close()
};
catch(e){};
};
</script>
</body>