cookies in HTA

A

Andrew Poulos

I'm using code adpated from quirksmode to read/write cookies. It seems
to work fine in a variety of browsers but when I try it in a HTA,
running on the local machine, no cookie values ever seem to be read and
I can't verify that a cookie has even been written. (Where does a HTA
hide cookies on a Windows XP box?)

Here's the code I'm using

fCreateCookie = function(name, value, days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
} else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
};

fReadCookie = function(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0; i < ca.length; i++) {
var c = ca;
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) {
return c.substring(nameEQ.length,c.length);
}
}
return null;
};

What needs to happen for cookies to work in a HTA running on the local
machine?

Andrew Poulos
 
A

Andrew Poulos

Andrew said:
I'm using code adpated from quirksmode to read/write cookies. It seems
to work fine in a variety of browsers but when I try it in a HTA,
running on the local machine, no cookie values ever seem to be read and
I can't verify that a cookie has even been written. (Where does a HTA
hide cookies on a Windows XP box?)

Here's the code I'm using

fCreateCookie = function(name, value, days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
} else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
};

fReadCookie = function(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0; i < ca.length; i++) {
var c = ca;
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) {
return c.substring(nameEQ.length,c.length);
}
}
return null;
};

What needs to happen for cookies to work in a HTA running on the local
machine?


Its ok now, I found the error. I neglected to set the number of days
before the cookie expires.

Andrew Poulos
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top