F
FishKeeper
I'm trying to write JavaScript code to test whether cookies are enabled
by writing a cookie and then reading its value. My code works fine in
Firefox, but it's not working in Internet Explorer 6. I have my
privacy settings set to block all cookies, but my JavaScript can read
and write cookies. Does this setting just block server cookies? That
doesn't seem right. I can't find any other settings that deal with
cookies in IE.
Here's a sample of my code which appears withinin the Body tag.
<script language="JavaScript">
//Verify that cookies are enabled for this site.
dtDate = new Date();
document.cookie = "MyTestCookie=MYWEB" + dtDate.toGMTString();
var strCookies = document.cookie;
var intPosition = strCookies.indexOf("MyTestCookie=MYWEB" +
dtDate.toGMTString());
alert(strCookies); //In IE, this displays my cookie that
SHOULDN'T get created.
if(intPosition==-1){
alert("Cookie not found!");
document.writeln("<tr><td height=\'30\'></td></tr>" +
"<tr><td align=\'center\'>" +
"<table border=\'1\' cellpadding=\'1\'
cellspacing=\'1\'><tr>"+
"<td align=\'center\'>IMPORTANT!!! Cookies
are not enabled. You must have cookies enabled to use this web
site.</td>" +
"</tr></table></td></tr>");
}
</script>
by writing a cookie and then reading its value. My code works fine in
Firefox, but it's not working in Internet Explorer 6. I have my
privacy settings set to block all cookies, but my JavaScript can read
and write cookies. Does this setting just block server cookies? That
doesn't seem right. I can't find any other settings that deal with
cookies in IE.
Here's a sample of my code which appears withinin the Body tag.
<script language="JavaScript">
//Verify that cookies are enabled for this site.
dtDate = new Date();
document.cookie = "MyTestCookie=MYWEB" + dtDate.toGMTString();
var strCookies = document.cookie;
var intPosition = strCookies.indexOf("MyTestCookie=MYWEB" +
dtDate.toGMTString());
alert(strCookies); //In IE, this displays my cookie that
SHOULDN'T get created.
if(intPosition==-1){
alert("Cookie not found!");
document.writeln("<tr><td height=\'30\'></td></tr>" +
"<tr><td align=\'center\'>" +
"<table border=\'1\' cellpadding=\'1\'
cellspacing=\'1\'><tr>"+
"<td align=\'center\'>IMPORTANT!!! Cookies
are not enabled. You must have cookies enabled to use this web
site.</td>" +
"</tr></table></td></tr>");
}
</script>