jquery - Javascript cookie not saving when user input reaches a certain size -


i trying save user input textarea in javascript cookie on unload of page , read textarea when user returns. issue having cookie not saving when user input reaches length. seems working fine small strings.

here html:

<html> <head> <title>cookie test</title> <link rel="stylesheet" type="text/css" href="css/site.css"> </head> <body class="full" onload="getcookies()" onunload="writecookies()">     <div class="fullscreen-overlay" id="fullscreen_overlay">   <div class="fullscreen-container js-fullscreen-container"> <div class="textarea-wrap">   <textarea name="fullscreen-contents" id="fullscreen-contents"></textarea> </div>  </div> </div> </body> </html> 

javascript:

function writecookies() {         var d = new date();         var n = document.getelementbyid('fullscreen-contents').value;         d.setdate(d.getdate() + 1);         document.cookie = "maincookie = " + n + "; expires = " + d.togmtstring() + "";     }      function getcookie(cname) {         var name = cname + "=";         var ca = document.cookie.split(';');         (var = 0; < ca.length; i++) {             var c = ca[i];             while (c.charat(0) == ' ') c = c.substring(1);             if (c.indexof(name) == 0) return c.substring(name.length, c.length);         }         return "";     }      function getcookies() {         document.getelementbyid('fullscreen-contents').value = getcookie('maincookie');     } 

any ideas going on? thanks!

the max size of cookie 4093 bytes. perhaps long string eclipsing limit. consider localstorage or sessionstorage instead

var text = document.getelementbyid('fullscreen-contents');  function savetext() {   localstorage.savedtext = text.value;   console.log("saved"); }  function gettext() {   if (localstorage.savedtext) {     text.value = localstorage.savedtext;     console.log("loaded");   } } 

edited: here fiddle


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -