日期:2014-05-18  浏览次数:20532 次

怎样打印cookie过期的时间?【用javascript】
我知道怎样 设置 cookie的过期时间了。用javascript。


但是怎样 alert 这个时间?


alert(document.cookie.time) ?这样是错的。应该怎样?谢谢

------解决方案--------------------
來自SDK文檔:

int loop1, loop2;
HttpCookieCollection MyCookieColl;
HttpCookie MyCookie;

MyCookieColl = Request.Cookies;

// Capture all cookie names into a string array.
String[] arr1 = MyCookieColl.AllKeys;

// Grab individual cookie objects by cookie name.
for (loop1 = 0; loop1 < arr1.Length; loop1++)
{
MyCookie = MyCookieColl[arr1[loop1]];
Response.Write("Cookie: " + MyCookie.Name + "<br>");
Response.Write("Expires: " + MyCookie.Expires + "<br>"); /***/
Response.Write ("Secure:" + MyCookie.Secure + "<br>");

//Grab all values for single cookie into an object array.
String[] arr2 = MyCookie.Values.AllKeys;

//Loop through cookie Value collection and print all values.
for (loop2 = 0; loop2 < arr2.Length; loop2++)
{
Response.Write("Value" + loop2 + ": " + arr2[loop2] + "<br>");
}
}

------解决方案--------------------
time是不是一个保留字段?
建议换一个名称。
------解决方案--------------------
// utility function called by getCookie() 
function getCookieVal(offset) { 
var endstr = document.cookie.indexOf (";", offset); 
if (endstr == -1) { 
endstr = document.cookie.length; 

return unescape(document.cookie.substring(offset, endstr)); 


// primary function to retrieve cookie by name 
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;