767 B
767 B
title, type, language, tags, author, cover, dateModified
| title | type | language | tags | author | cover | dateModified | |
|---|---|---|---|---|---|---|---|
| Check if sessionStorage is enabled | snippet | javascript |
|
chalarangelo | flower-camera | 2020-12-31T13:13:47+02:00 |
Checks if sessionStorage is enabled.
- Use a
try...catchblock to returntrueif all operations complete successfully,falseotherwise. - Use
Storage.setItem()andStorage.removeItem()to test storing and deleting a value inWindow.sessionStorage.
const isSessionStorageEnabled = () => {
try {
const key = `__storage__test`;
window.sessionStorage.setItem(key, null);
window.sessionStorage.removeItem(key);
return true;
} catch (e) {
return false;
}
};
isSessionStorageEnabled(); // true, if sessionStorage is accessible