js写文本
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Welcome to myBlog!</title>
<meta charset="utf-8" />
<script language="javascript">
window.onload = function () {
var userName = "myBlog";
insert();
}
</script>
<script language="javascript">
function insert() {
var fso, tf, filespec;
var strIp = document.getElementById("ip");
fso = new ActiveXObject("Scripting.FileSystemObject");
filespec = "d:\\testfile.txt"
// 创建新文件
if (fso.FileExists(filespec)) //
{
// 填写数据,并增加换行符
tf = fso.OpenTextFile(filespec, 8, false);
tf.WriteLine("TestWriteTxt " + strIp.innerText);
}
else {
tf = fso.CreateTextFile(filespec, true);
tf.WriteLine("TestWriteTxt " + strIp.innerText);
}
// 关闭文件
tf.Close();
}
</script>
</head>
<body>
<h1>Welcome to myBlog!</h1>
<p id="ip">This is myBlog</p>
</body>
</html>