You need to check browser support for localStorage and sessionStorage before using web storage,
if (typeof Storage !== "undefined") { // Code for localStorage/sessionStorage. } else { // Sorry! No Web Storage support.. }