可不可以用javascript读取一个记事本文件里面的数据并且对这些数据进行增删查改?
解决方案 »
- 单选项卡和多选项卡浏览器关闭事件监控问题
- 有没有用过IE自带的webBrowser控件打印预览的大侠?
- undefined从何而来
- [求解]一个页有两个验证码 同时刷新问题!
- 如何使用js达到多个popup共存的效果
- 各位大哥求救,显示XML数据的问题!!!!!!!!
- 用JavaScript判断页面是否第一次加载
- 使用 FSO 如何不让IE出现提示信息框!! 在线等!!!
- Extjs4 grid查询框中的textfield取不到值,求指教
- 如何自动的把页面加入收藏夹呀!
- 求助高手:jquery+dtree 动态树问题
- IE 8下加载fusioncharts Flash报错 null' 为空或不是对象
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>pubs</title>
<style>
table {
border:2 groove blue;
position:absolute;
top:100;
left:300;
}
td {
border:1 ridge green;
}</style>
</head>
<script language="javascript">
var path="c:\\";
var fname="everyone.txt"
window.status="公告栏";
function getFname(){
if (txt1.value != "" && txt1.value != " "){
fname=txt1.value;
}
}
function savefile(){
var fso,file;
if (tbox1.value == ""){
alert("请输入您想要公告的信息,再存储!");
return;
}else{
getFname();
fso=new ActiveXObject("Scripting.FileSystemObject");
file = fso.CreateTextFile(path + fname,true);
file.WriteLine(tbox1.value);
file.close();
alert("完成!");
}
}
function readfile(){
var fso,str,file;
getFname();
fso = new ActiveXObject("Scripting.FileSystemObject");
str = "没有您的留言";
if (fso.FileExists(path + fname)){
file=fso.OpenTextFile(path + fname,1);
str=file.readall();
file.close();
}
tbox1.value = str;
}</script>
<body>
<table width="437" height="157" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="433" height="28">E-Mail:
<input type="text" id="txt1">
<button name="save" onClick="javascript:savefile()">存储</button>
<button name="read" onClick="javascript:readfile()">阅读</button>
</td>
</tr>
<tr>
<td height="23"><div align="center">公告内容</div></td>
</tr>
<tr>
<td><textarea name="tbox1" rows="18" cols="60"></textarea></td>
</tr>
</table>
</body>
</html>
fso = new ActiveXObject("Scripting.FileSystemObject");
if (fso.FileExists("文件名全称")){
file=fso.OpenTextFile("文件名全称",1);
str=file.readall(); //读入内容
file.close();//写入(追加而非覆盖)
fso=new ActiveXObject("Scripting.FileSystemObject");
' OpenTextFile Method needs a Const value
' ForAppending = 8 ForReading = 1, ForWriting = 2
file = fso.OpenTextFile("文件名全称",8,true);
file.WriteLine("要写入的内容");
file.close();
fso = new ActiveXObject("Scripting.FileSystemObject");
if (fso.FileExists("文件名全称")){
file=fso.OpenTextFile("文件名全称",1);
str=file.readall(); //读入内容
file.close();
}//写入(追加而非覆盖)
fso=new ActiveXObject("Scripting.FileSystemObject");
' OpenTextFile Method needs a Const value
' ForAppending = 8 ForReading = 1, ForWriting = 2
file = fso.OpenTextFile("文件名全称",8,true);
file.WriteLine("要写入的内容");
file.close();
但是要看运行环境,通常在网页中的js,是无法直接访问本地文件的,这样会产生安全问题。但是其它环境下,比如启用了相关ActiveX的IE,HTA程序,作为服务器端脚本语言的JS,以及某些浏览器支持使用JS编写的浏览器扩展等等,只要运行环境支持并赋予相应的权限,理论上JS是可以做任何事情的。
如果在其他环境下是可以的,比如WSH,HTA等(HTA其实就是个网页)