Last active
December 19, 2015 22:08
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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