The property document.cookie returns null (NS7.1/XP) even when the cookie manager shows the cookie has been set and valid.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Rahul_SenGupta
Posted On:   Monday, November 10, 2003 12:13 PM

The same code works in NS7.1 NT Version but errors in NS7.1 XP Version. The JS code extract is: function SetCookie(cookieName,cookieValue,nDays) { var today = new Date(); var expire = new Date(); var path = "/"; var domain = ".mydomain.com"; var secure = "false"; if (nDays==null || nDays==0) nDays=2; expire.setTime(today.getTime() + 3600000*24*nDays); document.cookie = cookieName + "=" + escape (cookieValue) + ((expire == null) ? "" : ("; expires=" + expire.toGMTString())) + ((path == null) ? "" : ("; path=" + path)) + ((domain == null) ? "" : ("; domain=" + domain)) + ((secure    More>>

The same code works in NS7.1 NT Version but errors in NS7.1 XP Version. The JS code extract is:

			
function SetCookie(cookieName,cookieValue,nDays) {
var today = new Date();
var expire = new Date();
var path = "/";
var domain = ".mydomain.com";
var secure = "false";
if (nDays==null || nDays==0) nDays=2;
expire.setTime(today.getTime() + 3600000*24*nDays);
document.cookie = cookieName + "=" + escape (cookieValue) + ((expire == null) ? "" : ("; expires=" + expire.toGMTString())) + ((path == null) ? "" : ("; path=" + path)) + ((domain == null) ? "" : ("; domain=" + domain)) + ((secure == true) ? "; secure" : "");
}
function GetCookie (name) {
var arg = name + "=";
var test ;
var allcookies=document.cookie+';' ;
var offset ;
var start ;
var end ;
alert('Debugging 1:allcookies value='+allcookies) ;
allcookies.concat(';') ;
offset = allcookies.indexOf(arg) ;
start = arg.length ;
alert('Stage 1-Length is:'+start) ;
if (offset != -1) {
start = offset + arg.length ;
end = allcookies.indexOf(";", start) ;
alert('Stage 2-End is:'+end) ;
if (end == -1) end = allcookies.length ;
test = allcookies.substring(start, end) ;
alert('Stage 3-Test is:'+test) ;
return unescape(test) ;
}
}
function CheckSettings() {
var cookievalue = 0 ;
SetCookie('tmpCookie', 'Check');
cookievalue = GetCookie('tmpCookie') ;
alert('Stage Final-cookievalue:'+cookievalue) ;
if (cookievalue == 'Check') {
window.document.forms[0].elements['userid'].value = 'Enter Login ID';
document.LOGINFORM.userid.focus();
}
else {
window.document.forms[0].elements['userid'].value = 'Error';
}
}
   <<Less

Re: The property document.cookie returns null (NS7.1/XP) even when the cookie manager shows the cookie has been set and valid.

Posted By:   Firat_Tiryaki  
Posted On:   Monday, November 10, 2003 01:41 PM

when you set the cookie at the client side with javascript, browsers sometimes fail to get them, because it's not getting the cookie by a response from the server, the page is loaded before. Try to refresh the page and see what happens...
About | Sitemap | Contact