Menu

gitpiper

isLocalStorageEnabled javascript Code Snippet in 2024

browserintermediate

Last Updated: 20 July 2024

Checks if localStorage is enabled.

  • Use a try...catch block to return true if all operations complete successfully, false otherwise.
  • Use Storage.setItem() and Storage.removeItem() to test storing and deleting a value in window.localStorage.
const isLocalStorageEnabled = () => { try { const key = `__storage__test`; window.localStorage.setItem(key, null); window.localStorage.removeItem(key); return true; } catch (e) { return false; } };
isLocalStorageEnabled(); // true, if localStorage is accessible

javascript snippet similar to isLocalStorageEnabled For You in July 2024

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2024 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️