Checks if sessionStorage
is enabled.
try...catch
block to return true
if all operations complete successfully, false
otherwise.Storage.setItem()
and Storage.removeItem()
to test storing and deleting a value in Window.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
JavaScript, Browser
Checks if localStorage
is enabled.
JavaScript, Browser
Checks if the given element has the specified class.
JavaScript, Browser
Checks if the user color scheme preference is dark
.