Guest User

localStorage

a guest
Feb 9th, 2018
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var hasStorage = (function() {
  2.       try {
  3.         window.localStorage.setItem('tabTest', 'tabTest');
  4.         window.localStorage.removeItem('tabTest');
  5.         return true;
  6.       } catch (exception) {
  7.         return false;
  8.       }
  9.     }());
  10.  
  11.     //удаление элемента
  12.     function removeStorage(name) {
  13.       if (hasStorage) {
  14.         window.localStorage.removeItem(name);
  15.       }
  16.     }
  17.  
  18.     //сохранение элемента
  19.     function setStorage(name, value) {
  20.       if (hasStorage) {
  21.         window.localStorage.setItem(name, value);
  22.       }
  23.     }
  24.  
  25.     //получение элемента
  26.     function getStorage(name) {
  27.       if (hasStorage) {
  28.         var value = window.localStorage.getItem(name);
  29.         return value;
  30.       }
  31.       return '';
  32.     }
Advertisement
Add Comment
Please, Sign In to add comment