小弟想用过JS保存页面指定内容到已有的txt文档内,请问该怎么实现呢?
目前只能实现先新建txt再添加内容:
<script language="javascript" > function saveTxt(arr){ var fso = new ActiveXObject("Scripting.FileSystemObject") var tf = fso.OpenTextFile("c:\testfile.txt", ForAppending,TristateFalse); tf.Write (arr); tf.Close(); } </script>
使用OpenTextFile函数得到FSO对象。
http://www.devguru.com/technologies/vbscript/quickref/filesystemobject_opentextfile.html
执行到第这里就出错了,可以帮忙看一下吗?
var fh = fso.OpenTextFile("c:\\Test1.txt", ForAppending, TristateFalse);
alert(3);
fh.WriteLine("add.......");
fh.Close();
alert(1);
@亦_枫:
<html>
<head>
<title>Apppend Write to a File</title>
<script language="javascript">
var fso = new ActiveXObject("Scripting.FileSystemObject")
//var tf = fso.CreateTextFile("C:\\temp\\html\\answer.txt", true);
var tf = fso.OpenTextFile("C:\\temp\\html\\answer.txt",8);
tf.Write ("append the text file testing");
tf.Close();
</script>
</head>
<body>
<p>Works!</p>
</body>
</html>
你再试试。
ForAppending应该只在VBScript引擎中定义,所以你换成数字即可。
学习了,呵呵