Sometimes browsers block the access to the localStorage,
like when you are browsing in incognito mode or private mode and so on... So checking if
the storage exists is not the best idea, because sometimes it exists, but is not
accessible.
You can use this
function:
function storageON() {
try {
localStorage.setItem("__test", "data");
} catch (e)
{
return false;
}
return true;
}
if
(storageON()) { /* DO SOMETHING */ }
No comments:
Post a Comment