title: Javascript document.cookie always returns empty string
body: <p>I have this real strange problem with client side javascript setting cookies. I'm developing a little 1 page demo at the moment to use cookies to store some 'preferences'. Please note that I can't use a server side language for this demo or any 3rd party jQuery plugins.</p>
  
  <p>So I've written a javascript object to set a cookie:</p>
  
  <pre><code>var cookie = {
    set: function (name,value,exdays) {
  
      var exdate = new Date();
      exdate.setDate(exdate.getDate() + exdays);
      var value = escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
      document.cookie=name + "=" + value;
      console.log(document.cookie);
    }
  }
  
  cookie.set('foo','bar',2);
  console.log(document.cookie);
  </code></pre>
  
  <p>It just returns an empty string. I've gone into Chrome console to see if I can do it via directly modifying <code>document.cookie</code></p>
  
  <pre><code>&gt; document.cookie = "foo=bar";
  "foo=bar"
  &gt; document.cookie
  ""
  </code></pre>
  
  <p>How do you set a cookie via client side javascript?</p>
  
  <p><strong>Edit: I am not in incognito mode and cookies are enabled.</strong></p>