title: How can I store a cookie in local storage with Javascript?
body: <p>I have an app for Android (and hopefully later iPhone) that is based on Javacript and is made into an app using Phonegap/Applaud.</p>
  
  <p>Unfortunately, setting and getting cookies is not working on Android, and this might be particular to the Android environment. I was advised that using "local storage" might be more reliable.</p>
  
  <p>However, I knew nothing about local storage until this morning, and so I'm struggling to get aquainted. From what I gather, it's basically just another place to save data with a different syntax. For my situation, I don't think it gives me any advantages over cookies other than the fact that Android is forcing me to use it. As a result, I'm hoping I can still leverage my existing code for setting and getting cookies, and not have to take on a whole new approach.</p>
  
  <p>Surely I can just do a test in my Javascript to see if there is local storage, and if so, store and retrieve my cookie data there, and if not, then just use cookies as normal?</p>
  
  <p><strong><em>Note 1:</em></strong> I searched Stack Overflow for similar questions, and there was <a href="https://stackoverflow.com/questions/8347200/local-storage-android-and-phonegap">this one which at first seems exactly what I'm talking about</a>, but it's too terse so I can't parse it to know what I should do with it. Also, I think it assumes the presence of libraries and code that I don't think I have. I also looked at <a href="https://stackoverflow.com/questions/6130480/write-local-storage-data-into-cookie-via-javascript">this question</a> but I think it's doing the reverse of what I'm after.</p>
  
  <p><strong><em>Note 2:</em></strong> This is my current code for getting and setting cookies (procured from somewhere on the web. Up until the Android problem, was rock solid reliable):</p>
  
  <pre><code>function getCookie(c_name)
  {
      var c_start = document.cookie.indexOf(c_name + "=");
  
      if (document.cookie.length &gt; 0)
      {
          if (c_start !== -1)
          {
              return getCookieSubstring(c_start, c_name);
          }
      }
      return "";
  }
  
  function setCookie(c_name, value, expiredays)
  {
          var exdate = new Date();
          exdate.setDate(exdate.getDate() + expiredays);
          document.cookie = c_name + "=" + escape(value) +
          ((expiredays === null) ? "" : ";expires=" + exdate.toUTCString());
          alert("this is document.cookie: " + document.cookie);
  }
  </code></pre>