I've recently noticed some issues with using cookies between ASP and Javascript. Anyone aware of any specific problems? Basically what I'm running into is that I set a cookie for a login value using ASP. I want to have a logout link and was trying to set the cookie value using Javascript. This appears to work. However, if I try to login again, the cookie value setting in ASP is not "sticking" and the cookie retains a logout value!?
As a test, I created an ASP page where session and saved cookie value are set using both ASP and Javascript. This text page exhibits the same kind of strange behavior and I can't make any sense of it. If you have the time, please take a look.
Here's the code for the test page...
Also, here is the source file for cookies.js...
Thanks in advance for any help or ideas.
Glenn
As a test, I created an ASP page where session and saved cookie value are set using both ASP and Javascript. This text page exhibits the same kind of strange behavior and I can't make any sense of it. If you have the time, please take a look.
Here's the code for the test page...
Code:
<%@ LANGUAGE=VBSCRIPT %>
<% Option Explicit %>
<% Response.Buffer = True %>
<html><head><title>Test Cookies</title>
<script src="includes/cookies.js" language="JavaScript" type="text/javascript"></script>
<script language="JavaScript" type="text/javascript">
<!--
var expDate = new Date();
expDate.setTime (expDate.getTime() + (10 * 60 * 1000));
//-->
</script>
</head>
<body>
<%
if request.cookies("session") = "" then
response.cookies("session") = "true"
else
response.write "<p>Session cookie = " & request.cookies("session")
response.cookies("session") = "true"
response.write "<br>After ASP cookie assignment, session cookie = " & request.cookies("session") & "</p>"
end if
if request.cookies("saved") = "" then
response.cookies("saved") = "true"
response.cookies("saved").expires = date() + 1
else
response.write "<p>Saved cookie = " & request.cookies("saved")
response.cookies("saved") = "true"
response.cookies("saved").expires = date() + 1
response.write "<br>After ASP cookie assignment, saved cookie = " & request.cookies("saved") & "</p>"
end if
%>
</p>
<a href="javascript:setCookie('session','false',null)">Set Session Cookie to False</a>
<br><a href="javascript:setCookie('saved','false',expDate)">Set Saved Cookie to False</a>
<form method="post" action="testCookies.asp" name="frm">
<input type="submit" name="btn" value="Submit">
</form>
</body>
</html>
Also, here is the source file for cookies.js...
Code:
function setCookie(name, value, expire)
{
document.cookie = name + "=" + escape(value) + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()));
}
function setExpiration(days)
{
var expires = new Date();
var today = new Date();
expires.setTime (today.getTime() + (1000*60^60^24*parseInt(days)));
return expires;
}
Thanks in advance for any help or ideas.
Glenn