title: JS Cookie set in 2 places, doesn't overwrite first set
body: <p>I am using the same script on 2 different pages, to set the same cookie. My assumption would be that even though the two pages are (slightly) different paths, they would simply overwrite the cookie instead of duplicating entries into it.</p>
  
  <p><em>My first page's path is:</em></p>
  
  <p><code>example.com/classifieds/businesses</code></p>
  
  <p><em>My second page's path is:</em></p>
  
  <p><code>example.com/classifieds/businesses/search</code></p>
  
  <p>So, my question is, are cookies page-dependent; can I force them to overwrite existing values instead of writing their own page-specific values to the cookie?</p>
  
  <p><em>Here is what my cookie looks like with the duplicates:</em></p>
  
  <p><code>domain=.example.com; path=/; bdView=column; bdView=detail; domain=.example.com;</code></p>
  
  <p><em>Code for setting domain (which is in the header file)</em></p>
  
  <pre><code>var domain = window.location.host.split(/\.(.+)/)[1];
  document.cookie = "domain=." + domain;
  document.cookie = "path=/";
  </code></pre>
  
  <p><em>Code for setting bdView (which is in a separate js file that I include in both pages)</em></p>
  
  <pre><code>function setCookie(view) {
      switch (view) {
          case "column":
              document.cookie = "bdView=column";
              break;
          case "list":
              document.cookie = "bdView=list";
              break;
          case "detail":
              document.cookie = "bdView=detail";
              break;
      }
  }
  </code></pre>