Gebruiker:JNB45/silent fail storage.js: verschil tussen versies
Verwijderde inhoud Toegevoegde inhoud
Nieuwe pagina aangemaakt met '// Copied from sv.wikt (sv:MediaWiki:Gadget-silent fail storage.js) // Local storage wrapper: the same as local storage, but fails silently if it // is not supp...' |
(geen verschil)
|
Versie van 19 dec 2016 22:06
// Copied from sv.wikt ([[sv:MediaWiki:Gadget-silent fail storage.js]])
// Local storage wrapper: the same as local storage, but fails silently if it
// is not supported.
window.silentFailStorage = (function () {
try {
// Will throw if localStorage isn't supported or if it's disabled
var l = window.localStorage,
val = l.getItem('a');
l.setItem('a', 'b');
if (l.getItem('a') === 'b') {
// it works
if (val !== null)
l.setItem('a', val);
else
l.removeItem('a');
return l;
}
} catch (e) {
}
function noop() {}
function rnull() { return null; }
return {
getItem: rnull,
setItem: noop,
removeItem: noop,
clear: noop,
key: rnull,
length: 0
};
})();