怎样得到一个网页文件的上次访问时间?

koolfoo 2002-04-16 10:18:47
在我的c:中已经有了一个.htm的文件,我怎么得到我对它的上次访问时间?
...全文
112 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
weidegong 2002-04-16
  • 打赏
  • 举报
回复
<script language=javascript>

function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}

function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function SetCookie (name, value) {
var the_date = new Date("December 31, 3666");
var the_cookie_date =the_date.toGMTString();
document.cookie = name + "=" + escape (value)+ ";expires=" +the_cookie_date;
}


function window.onload(){//B页面打开时设置cookieA=B
var last=GetCookie("cookieA");
if(last) {
var temp=last.split(";");
alert("The last time you visit this page is:"+temp[0]);
}
else
alert("欢迎您第一次访问!");
}

function window.onunload(){//B页面打开时设置cookieA=B
var d=new Date();
SetCookie("cookieA",d)
}

function acceptA(){//接收cookieA,并进行处理
if(GetCookie("cookieA")=="0"){
self.opener=null;
self.close();
}
}
</script>
8988 2002-04-16
  • 打赏
  • 举报
回复
也可用Application记录上次访问时间,方法如下:
<%
oldtime=Application("oldtime")
Application("oldtime")=now()
%>
<%="最后一次访问的时间是:" & formatdatetime(oldtime,1) & " " & formatdatetime(oldtime,4)%>

weidegong 2002-04-16
  • 打赏
  • 举报
回复
Cookie
8988 2002-04-16
  • 打赏
  • 举报
回复
还者用服务器Application对象记录下来。
8988 2002-04-16
  • 打赏
  • 举报
回复
这需要将上次访问的时间保存一下(保存到数据库或文本文件中)
下次访问时,再取出来显示。

87,915

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧