Skip to content

Instantly share code, notes, and snippets.

@aleckyann
Last active January 27, 2017 18:25
Show Gist options
  • Save aleckyann/bd1ba5a723715bfb239b07e80ec23e2e to your computer and use it in GitHub Desktop.
Save aleckyann/bd1ba5a723715bfb239b07e80ec23e2e to your computer and use it in GitHub Desktop.
removeEventListener not work
function nulo (event) {
return true;
}
if(sessionStorage.getItem('enterToSend') === 'true'){
document.getElementById('enterToSend').setAttribute('checked', true);
document.getElementById('mensagem').addEventListener('keydown', function(e) {
if(e.keyCode == 13) {
document.getElementById('enviaMensagem').click();
}
});
} else {
document.getElementById('enterToSend').removeAttribute('checked'); //remove checked do checkbox
document.getElementById('mensagem').removeEventListener('keydown', nulo);
}
function enterToSend(e){
if(sessionStorage.getItem('enterToSend') === 'false'){//Enviar com enter!
sessionStorage.setItem('enterToSend', 'true');
document.addEventListener('keydown', function(e){
if(e.keyCode == 13){
document.getElementById('enviaMensagem').click()
}
});
}else{
document.removeEventListener('keydown', nulo); //remove envento com enter
sessionStorage.setItem('enterToSend', 'false');
}
}
(function initEnterToSend(){
if(sessionStorage.getItem('enterToSend') === null){
sessionStorage.setItem('enterToSend', 'false');
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment