arrays - Unable to load more than 23 items from jquery cookie -
this question has answer here:
i looking way save/load array jquery cookie , used top answer of question how store array in jquery cookie? can add many items cookie list want , right number when check array length. refresh page , load cookie list, maximum of 23 items in array, , can't find reason it.
here's code
//this not production quality, demo code. var cookielist = function(cookiename) { //when cookie saved items comma seperated string //so split cookie comma original array var cookie = $.cookie(cookiename); //load items or new array if null. var items = cookie ? cookie.split(/,/) : new array(); //return object can use access array. //while hiding direct access declared items array //this called closures see http://www.jibbering.com/faq/faq_notes/closures.html return { "add": function(val) { //add items. items.push(val); //save items cookie. //edit: modified linked answer nick see // http://stackoverflow.com/questions/3387251/how-to-store-array-in-jquery-cookie $.cookie(cookiename, items.join(',')); }, "remove": function (val) { //edit: thx assef , luke remove. indx = items.indexof(val); if(indx!=-1) items.splice(indx, 1); $.cookie(cookiename, items.join(',')); }, "clear": function() { items = []; //clear cookie. //$.cookie(cookiename, ''); $.removecookie(cookiename); }, "items": function() { //get items. return items; } } } var packcollectorcookielist = new cookielist("xweaselpackcollector"); // items in array. var comparelistcollector = packcollectorcookielist.items(); alert(comparelistcollector.length);
and add items (which links) like
packcollectorcookielist.add($(this).parent('li').data('link'));
the standard cookie size browsers 4096. might triggering limit in 1 or both of:
size limit of data in 1 cookie
multiple cookies have not expired adding 4096.
html5 , jquery both support local storage bypass issue.
Comments
Post a Comment