Skip to content

Instantly share code, notes, and snippets.

@gustavopaes
Last active December 19, 2015 22:08
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gustavopaes/6024904 to your computer and use it in GitHub Desktop.
Save gustavopaes/6024904 to your computer and use it in GitHub Desktop.
Verifica se o navegador possui suporte ativo / liberado para o uso da API localStorage.
/**
* Valida se o usuário está habilitado para usar a API localStorage.
* https://gist.github.com/gustavopaes/6024904
* @type {Boolean}
*/
var storageValidation = (function(window) {
'use strict';
var validation;
try {
// IE <= 9 e demais navegadores devem retornar TRUE
validation = !!window.localStorage;
// Se estiver em modo Private no Safari, DOM Exception será retornado,
// alegando falta de espaço para armazenamento.
if(validation === true) {
localStorage.setItem('__test', '');
localStorage.removeItem('__test');
}
} catch(e) {
// possível erro de Access Denied no IE 10 ou
// modo private no Safari.
validation = false;
}
return validation;
}(window));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment