事實上客戶機上的Cookie字典是以字符串的形式存在:
info=Myname=jeff&Gender=male&Myheight=172
如果用戶沒有指定“子鍵”名而直接引用Cookies變量,將會返回一個包含所有的“子鍵”名及值的字符串。例如上面這個例子包含三個“子鍵”:"Myname"、"Gender"和"Myheight",當用戶沒有指定其“子鍵”而直接通過Request.Cookies("info")來引用時,則會得到下列字符串:
info=Myname=jeff&Gender=male&Myheight=172
如果要把Cookie中讀取的所有數據,可以用下面的代碼得到:
復制代碼 代碼如下:
<%For each cookie in Request.Cookies
if Not cookie.HasKeys then
Response.write cookie & "=" & Request.Cookies(cookie)
Else
for each key in Request.Cookies(cookie)
Response.write cookie&"("&key&")"&"="& Request.Cookies(cookie)(key)
next
end if
next
%>
下面是具體的在頁面中記錄查詢的記錄的代碼
復制代碼 代碼如下:
Sub SetCookie
Dim C_DomainList,C_i
C_DomainList=Request.Cookies("jb51")("C_DomainList")
If Domain<>"" and C_DomainList<>"" then
If not instr(C_DomainList,Domain&"|")>0 then C_DomainList=Domain&"|"&C_DomainList
End if
If Domain<>"" and C_DomainList="" then
C_DomainList=Domain&"|"
End if
If C_DomainList<>"" then
Response.write "<div id=C_domainlist>您關注的站點:"
C_arrDomain = split(C_DomainList,"|")
C_DomainList=""
numDomain=ubound(C_arrDomain)-1
If numDomain>4 then numDomain=4
for C_i=0 to numDomain
Response.write " <a href=?url="&C_arrDomain(C_i)&">"&C_arrDomain(C_i)&"</a> |"
C_DomainList=C_DomainList&C_arrDomain(C_i)&"|"
next
Response.Cookies("jb51")("C_DomainList")=C_DomainList
Response.Cookies("jb51").Expires=Date+30
Response.write "<a href=#cursor:pointer"" onClick=""clearCookie('jb51');alert('已清除記錄!');"">清除記錄</a></div>"
End If
End Sub
該文章在 2010/11/26 8:54:22 編輯過