I wanted to know if it's necessary to do a check if local storage is present or not when I try to use it.
Ie, I have this as a check:
if (global.localStorage) {
global.localStorage.setItem('layout', JSON.stringify({
[key]: value
}));
}
Or can I use localStorage without this check?
localStorage browser support To be sure the browser supports localStorage , you can check using the following snippet: if (typeof(Storage) !== "undefined") { // Code for localStorage } else { // No web storage Support. }
Google Chrome/ChromiumChrome treats cookies and local storage as the same thing, so these steps work for both. Click on the menu button in the top-right corner of your Chrome window. Select “Settings” from that menu. Click “Cookies and site permissions”.
Just go to the developer tools by pressing F12 , then go to the Application tab. In the Storage section expand Local Storage. After that, you'll see all your browser's local storage there. In Chrome version 65, you can manually modify and add new items.
Mozilla maintain a table of desktop and mobile browser support here: https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage
You can see the full list of supported browsers here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With