View Full Version : Cookies and Internet Explorer

04-21-2005, 06:29 AM
I'm trying to have a user who visits my site be able to select the style sheet they'd like to see and it save as a cookie. I was given some javascript that would help me out and it has to a certain extent. With firefox the user can select the style and it saves, all is well. With Internet Explorer 6 and Service Pack 2 installed the style doesn't get saved and it reverts back to the default. I've tested this on several computers all with Service Pack 2 and IE6. I have no idea why it does. I don't get any errors. If anyone could help me out that would be great, I am very new to Javascript and know nothing about it. My site is www.dempsey.cjb.net and here is the javascript that I currently use.



function changeStyle( oSel )
{ if (sCSS = oSel.value)
{ setStyle( sCSS );
var expires = new Date( 2010, 1, 1 );
document.cookie = CSS_COOKIE_VAR + "=" + escape( sCSS ) +"; expires=" + expires.toGMTString() + ";" ;

function setStyle( sCSS )
{ document.getElementById("external_style").href = sCSS;

function loadStyle()
{ aCookie = document.cookie.split(";");
for (i=0; i< aCookie.length; i++)
{ aName = aCookie[i].split("=");
if (aName[0] == CSS_COOKIE_VAR )
{ setStyle( aName[1] );
document.getElementById("control").value = aName[1];

04-21-2005, 06:41 AM
Maybe cookie is disabled in the settings?

04-21-2005, 06:48 AM
Thanks for your quick reply. Well it was tried at several different computers, the people who did it wouldn't know how to turn cookies off. I know on my computer they aren't turned off. Is that what you mean?

04-21-2005, 07:57 AM
Try alerting document.cookie after it is set and as the style is loaded. I have no IE SP2 so I can't see the default cookie settings but I know that with SP2, IE becomes stricter. Look at the Privacy tab of the Internet Options.

04-21-2005, 03:21 PM
I'm sorry glenngv but i'm really new at javascript could you perhaps fully write out exactly what I should try, I have no clue how to go about what you suggested. Thanks for your help. I really do appreciate it.

04-22-2005, 03:15 AM
any help would be appreciated.