title: Save Cookies, Then Open Link in New Tab
body: <p>I have some javascript code that saves a cookie. However, if after saving the cookie, the user opens a new tab, it appears that the cookie is not saved. The new tab is on the same domain.</p>
  
  <p>Here is my cookie setting/getting code:</p>
  
  <pre><code>function setCookie(c_name,value,exdays)
  {
      var exdate=new Date();
      exdate.setDate(exdate.getDate() + exdays);
      var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
      document.cookie=c_name + "=" + c_value;
  }
  
  function getCookie(c_name)
  {
      var i,x,y,ARRcookies=document.cookie.split(";");
      for (i=0;i&lt;ARRcookies.length;i++) {
          x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
          y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
          x=x.replace(/^\s+|\s+$/g,"");
          if (x==c_name) {
              return unescape(y);
          }
      }
  }
  </code></pre>
  
  <p>If some javascript calls <code>setCookie('mycookie', 1)</code> and then the user clicks on a link where the <code>_target</code> is set to <code>_blank</code>, the cookie does not load in the new tab. So <code>getCookie('mycookie')</code> will not return <code>1</code>.</p>
  
  <p>What is the problem here?</p>