650 B
650 B
title, tags
| title | tags |
|---|---|
| isSessionStorageEnabled | browser,intermediate |
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