con.close();
con = null;
}
con = null;
}
function getcountfromtxt() {
var filepath = location.href.substring(0, location.href.indexof("cnt.htm"));
var path = filepath + "count.txt";
path = path.substring(8);
var nextcnt = 0;
var filepath = location.href.substring(0, location.href.indexof("cnt.htm"));
var path = filepath + "count.txt";
path = path.substring(8);
var nextcnt = 0;
var fso, f1, ts, s;
//以只读方式打开文本文件。
var forreading = 1;
var forreading = 1;
//以读写方式打开文本文件。
var forwriting = 2;
var forwriting = 2;
fso = new activexobject("scripting.filesystemobject");
f1 = fso.getfile(path);
ts = f1.openastextstream(forreading, true);
s = ts.readline();
nextcnt = eval(s) + 1;
document.write("now count is :" + s);
ts.close();
f1 = fso.getfile(path);
ts = f1.openastextstream(forreading, true);
s = ts.readline();
nextcnt = eval(s) + 1;
document.write("now count is :" + s);
ts.close();
ts = f1.openastextstream(forwriting, true);
ts.writeline(nextcnt);
ts.close();
}
//-->
</script>
</head>
ts.writeline(nextcnt);
ts.close();
}
//-->
</script>
</head>
<body>
<script language="javascript">
<!--
getcountfromtxt();
//-->
</script>
</body>
</html>
<script language="javascript">
<!--
getcountfromtxt();
//-->
</script>
</body>
</html>
后记:虽然在只支持静态页面的免费空间不可用,但是我想一些支持
asp的免费空间应该能用,当然我没有具体试过,只是凭自己想象。
并且用这种方法来读写数据库,只适合做计数器和留言版这样的不需
要保密性的工作,毕竟代码全是用javascript写成的,谁都可以看到,
然后就可以得到路径把db文件下载下来进行分析,所以没办法用它来
保存一些不想让别人知道的东西。
就像我一个同事说的,用javascript连接数据库进行操作,简直就是
霸王硬上弓,呵呵,的确如此,既然不能用在免费空间上作自己的计