The function setItem, beginning on line 98 of jquery.total-storage.js, has a bug in it:
setItem: function(key, value){
if (!supported){
try {
$.cookie(key, value);
return value;
} catch(e){
console.log('Local Storage not supported by this browser. Install the cookie plugin on your site to take advantage of the same functionality. You can get it at https://github.com/carhartl/jquery-cookie');
}
}
var saver = JSON.stringify(value);
ls.setItem(key, saver);
return this.parseResult(saver);
}
This code fails to stringify value if localStorage is not supported. A fixed version of the function follows:
setItem: function(key, value){
var saver = JSON.stringify(value);
if (!supported){
try {
$.cookie(key, saver);
} catch(e){
if (window.console) { console.log('Local Storage not supported by this browser. Install the cookie plugin on your site to take advantage of the same functionality. You can get it at https://github.com/carhartl/jquery-cookie'); }
}
} else {
ls.setItem(key, saver);
}
return this.parseResult(saver);
}
Note that I've also added a check for window.console, as this prevents an error in IE7 ("console is undefined").
The function setItem, beginning on line 98 of jquery.total-storage.js, has a bug in it:
This code fails to stringify value if localStorage is not supported. A fixed version of the function follows:
Note that I've also added a check for window.console, as this prevents an error in IE7 ("console is undefined").