以下内容为程序代码
|
显示在线用户数量的页面
以下内容为程序代码
|
这种方法则避免了以上的弊病,经实践,效果不错(例子:www。atersoft。com/bbs),具体如下:
假定index。htm为框架网页,包含id=left,id=top和id=bottom的三个框架
1、做个统计页面usernum。asp
<p>正在统计数据。。。</p>
<%
user=request.querystring("user")
if user=0 then '如果离开则人数-1
application.lock
application("num")=application("num")-1
application.unlock
response.write "<script>self.close();</script>"
elseif user=1 then '如果进入则+1
application.lock
application("num")=application("num")+1
application.unlock
end if
%>
2、在框架页面中如(index。htm)嵌入usernum。asp
<body onbeforeunload="window.open('usernum.asp?user=0','num','menubar=no')">
......
<iframe src="usernum.asp?user=1" frameborder=0 width=0 height=0></iframe>
3、在需要显示人数的页面(假定在left显示)中加入
<div id=num><%=application("num")%></div>
4、设定需要更新数据的页面(如bottom)
function tj(){
top.left.num.innerhtml=<%=application("num")%>;
}
<body onload="tj()">
完毕,这只是一个例子,具体应用可以灵活,另外,为什么当离开时要window。open usernum。asp呢?因为如果同样放在ifrme中,窗口关得太快,usernum。asp页面来不及装载就关掉了无法减少人数
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!