words

HTML5 localstorage ‘illegal access’ bugfix

/*
 * This will cause 'illegal access' exception 
 * on Android ~2.3 inbuilt browsers if getItem() returns 'null'
 * cuz JSON.parse can not handle null as a parameter
*/
var  a = JSON.parse(localStorage.getItem(_key));

/*
 * Possible easy solution
*/
var  a = localStorage.getItem(_key) ? JSON.parse(localStorage.getItem(_key)) : null;
Last updated: