10 examples of 'localstorage in jquery' in JavaScript

Every line of 'localstorage in jquery' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
257function checkForLocalStorage() {
258 try {
259 localStorage.setItem('test', 'test');
260 localStorage.removeItem('test');
261 return true;
262 } catch (e) {
263 return false;
264 }
265}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

38function getLocalStorage(key) {
39 return localStorage.getItem(key);
40};
314public static hasLocalStorage():boolean
315{
316 try
317 {
318 return ('localStorage' in window) && window.localStorage !== null;
319 }
320 catch (error)
321 {
322 return false;
323 }
324}
311function getLocalStorage (currentControl, key) {
312 if (key in store) {
313 const stored = store[key];
314 if (!stored) return undefined;
315 if (currentControl.type !== stored.type) return undefined;
316 if (currentControl.value !== stored.defaultValue) return undefined;
317 // console.log('CHECK CHECK', key, currentControl.value, stored.defaultValue)
318 return stored.value;
319 }
320 return undefined;
321}
35function isLocalStorageAvailable() {
36 try {
37 return 'localStorage' in window && window['localStorage'] !== null;
38 } catch (e) {
39 console.log("localStorage_failed:", e);
40 return false;
41 }
42};
330function localStorageGet(key) {
331 return (window.localStorage || {})[key] === 'true';
332}
54export function localStorageExists() {
55 return lsExists;
56}
640function localStorageGetItem(key, defaultValue)
641{
642 var result = null;
643 if (!!window.localStorage) {
644 result = localStorage.getItem(key);
645 }
646 if (result === null) {
647 result = defaultValue;
648 }
649 return result;
650}
163function getLocalStorageStr(key, defaultValue) {
164 return window.localStorage[key] || defaultValue;
165}
4export function hasLocalStorage(): boolean {
5 if (hasLocalStorageCache) {
6 return hasLocalStorageCache;
7 }
8
9 // hasLocalStorage is used to safely ensure we can use localStorage
10 // taken from https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API#Feature-detecting_localStorage
11 let storage = window['localStorage'];
12 try {
13 let x = '__storage_test__';
14 storage.setItem(x, x);
15 storage.removeItem(x);
16 hasLocalStorageCache = true;
17 }
18 catch (e) {
19 hasLocalStorageCache = e instanceof DOMException && (
20 // everything except Firefox
21 e.code === 22 ||
22 // Firefox
23 e.code === 1014 ||
24 // test name field too, because code might not be present
25 // everything except Firefox
26 e.name === 'QuotaExceededError' ||
27 // Firefox
28 e.name === 'NS_ERROR_DOM_QUOTA_REACHED') &&
29 // acknowledge QuotaExceededError only if there's something already stored
30 storage.length !== 0;
31 }
32 return hasLocalStorageCache;
33}

Related snippets