Показать сообщение отдельно
  #13 (permalink)  
Старый 27.01.2017, 12:49
Аспирант
Отправить личное сообщение для ExXxTaSy Посмотреть профиль Найти все сообщения от ExXxTaSy
 
Регистрация: 25.07.2012
Сообщений: 32

вопрос решил так:
var fakeLocalStorage = function() {
        var fakeLocalStorage = {},
            storage;
         
        // If Storage exists we modify it to write to our fakeLocalStorage object instead.
        // If Storage does not exist we create an empty object.
        if (window.Storage && window.localStorage) {
            storage = window.Storage.prototype;
        } else {
            // We don't bother implementing a fake Storage object
            window.localStorage = {};
            storage = window.localStorage;
        }

        // For older IE
        if (!window.location.origin) {
            window.location.origin = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ':' + window.location.port: '');
        }

        var dispatchStorageEvent = function(key, newValue) {
            var oldValue = (key == null) ? null : storage.getItem(key), // `==` to match both null and undefined
                url = location.href.substr(location.origin.length),
                storageEvent = document.createEvent('StorageEvent'); // For IE,  

            storageEvent.initStorageEvent('storage', false, false, key, oldValue, newValue, url, null);
            window.dispatchEvent(storageEvent);
        };

        storage.key = function(i) {
            var key = Object.keys(fakeLocalStorage)[i];
            return typeof key === 'string' ? key : null;
        };

        storage.getItem = function(key) {
            return typeof fakeLocalStorage[key] === 'string' ? fakeLocalStorage[key] : null;
        };

        storage.setItem = function(key, value) {
            dispatchStorageEvent(key, value);
            fakeLocalStorage[key] = String(value);
        };

        storage.removeItem = function(key) {
            dispatchStorageEvent(key, null);
            delete fakeLocalStorage[key];
        };

        storage.clear = function() {
            dispatchStorageEvent(null, null);
            fakeLocalStorage = {};
        };
    };

    //
    if (typeof window.localStorage === 'object') {
        try {
            localStorage.setItem('localStorageTest', 1);
            localStorage.removeItem('localStorageTest');
        } catch (e) {
            fakeLocalStorage();
        }
    } else {
        // Use fake localStorage for any browser that does not support it.
        fakeLocalStorage();
    }
Ответить с цитированием