Reading cookies working in Firefox/IE, NOT Chrome
<p>I've got a code that works to change style sheets and saving them in cookies in Firefox and IE but it doesn't work in Chrome. </p>

<p>This is the code I'm using:</p>

<pre><code>&lt;head&gt;
&lt;link href="default.css" title="default" rel="stylesheet" type="text/css" /&gt;
&lt;link href="theme1.css" title="theme1" rel="stylesheet" type="text/css" /&gt;
&lt;link href="theme2.css" title="theme2" rel="stylesheet" type="text/css" /&gt;
&lt;link href="theme3.css" title="theme3" rel="stylesheet" type="text/css" /&gt;

&lt;script type="text/javascript" src="javascript.js"&gt;&lt;/script&gt;

&lt;/head&gt;
&lt;body&gt;
&lt;ul id="dropdown"&gt;
&lt;li&gt; Choose theme
    &lt;ul&gt; 
        &lt;li id="stylesheet1" &gt; &lt;a href="#"&gt; Default &lt;/a&gt;&lt;/li&gt;
        &lt;li id="stylesheet2" &gt; &lt;a href="#"&gt; Theme 1 &lt;/a&gt;&lt;/li&gt;
        &lt;li id="stylesheet3" &gt; &lt;a href="#"&gt; Theme 2 &lt;/a&gt;&lt;/li&gt;
        &lt;li id="stylesheet4" &gt; &lt;a href="#"&gt; Theme 3 &lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt; 


&lt;/body&gt;
</code></pre>

<p>And the javascript.js contains this:</p>

<pre><code>function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 &amp;&amp; a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  } 
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 &amp;&amp; a.getAttribute("title") &amp;&amp; !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       &amp;&amp; a.getAttribute("rel").indexOf("alt") == -1
       &amp;&amp; a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

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

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



window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}



var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);


function initate()
{

document.getElementById("stylesheet1").onclick = function() {
   setActiveStyleSheet("default");
   return false
};
document.getElementById("stylesheet2").onclick = function() {
   setActiveStyleSheet("theme1");
   return false
};
document.getElementById("stylesheet3").onclick = function() {
   setActiveStyleSheet("theme2");
   return false
};
document.getElementById("stylesheet4").onclick = function() {
   setActiveStyleSheet("theme3");
   return false
}

}

window.onload = initate;
</code></pre>

<p>It does work to change the style sheet in Chrome but when I reload the page it doesn't keep the chosen style sheet like it does in IE and Firefox. I can't figure why it doesn't work in Chrome. I'm new to javascript and most of the code used is not written by me but taken from different places so I don't really understand most of it. </p>
