Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Olá pessoal, como todos sabem estou construindo um Chat, que está usando muito javascript, mas eu não sei muito não...
Agora preciso que se anule o botão refresh, no IE eu consegui, agora soh falta no firefox... algéum me ajuda?
Pode ser link, código pronto ou ajeitar este que vou por abaixo pra que o miserável do FF, não aceite o F5...
quanto ao botão atualizar do menu do botão, este não tem problema.
Segue o códiog que eu tenho - SOMENTE PRO IE....
document.onkeydown = function(){
if(window.event && window.event.keyCode == 116)
{ // Capture and remap F5
window.event.keyCode = 505;
}
if(window.event && window.event.keyCode == 505)
{ // New action for F5
alert('Função Desabilitada');
return false;
// Must return false or the browser will refresh anyway
}
}Jah tinha visto, mas não consegui fazer desabilitar soh o F5
e o restante, control alt, shift... tah tudo bloqueado.... soh caracteres.... isso aki oh...//allow these keys inside a text box if (sTag == "textarea" || (sTag == "input" && (sTagType == "text" || sTagType == "password")) && (nKeyCode == asciiBack || nKeyCode == asciiSHIFT || nKeyCode == asciiHome || bShiftPressed || (bCtrlPressed && (nKeyCode == asciiLeftArrow || nKeyCode == asciiRightArrow)))){ return true; } else if(bAltPressed && (nKeyCode == asciiLeftArrow || nKeyCode == asciiRightArrow)){ // block alt + left or right arrow bRet = false; }else if(bCtrlPressed && (sChar == 'A' || sChar == 'C' || sChar == 'V' || sChar == 'X')){ // ALLOW cut, copy and paste, and SELECT ALL bRet = true; }else if(bShiftPressed && nKeyCode == asciiTab){//allow shift + tab bRet = true; }else if(bIsFunctionKey){ // Capture and stop these keys bRet = false; }else if(bCtrlPressed || bShiftPressed || bAltPressed){ //block ALL other sequences, includes CTRL+O, CTRL+P, CTRL+N, etc.... bRet = false; } soh tah funcionando no firefox... portanto queria tirar, pra facilitar....
Não... tranquilo... soh queria poder tirar sem dar pau na função.... no final quando achar que está ok, posto aqui pra vcs testarem ok?
OH! Acho que eras isso.... Bloqueia F5, Alt+ <- e Alt + -> ou seja, somente via navegação....var msg = 'Função desativada!'; //ESSAS SERÃO AS TECLAS DESABILITADAS var asciiF5 = 116; var asciiALT = 18; var asciiLeftArrow = 37; var asciiRightArrow = 39; if(document.all){ //ie has to block in the key down document.onkeydown = onKeyPress; }else if (document.layers || document.getElementById){ //NS and mozilla have to block in the key press document.onkeypress = onKeyPress; } function onKeyPress(evt) { window.status = ''; var oEvent = (window.event) ? window.event : evt; var nKeyCode = oEvent.keyCode ? oEvent.keyCode : oEvent.which ? oEvent.which : void 0; var bIsFunctionKey = false; if(oEvent.charCode == null || oEvent.charCode == 0){ bIsFunctionKey = (nKeyCode == asciiF5) || ( nKeyCode == asciiALT ) } var sChar = String.fromCharCode(nKeyCode).toUpperCase(); var oTarget = (oEvent.target) ? oEvent.target : oEvent.srcElement; var sTag = oTarget.tagName.toLowerCase(); var sTagType = oTarget.getAttribute("type"); var bAltPressed = (oEvent.altKey) ? oEvent.altKey : oEvent.modifiers & 1 > 0; var bRet = true; if(sTagType != null){sTagType = sTagType.toLowerCase();} if(bIsFunctionKey){ bRet = false; } else if(bAltPressed && (nKeyCode == asciiLeftArrow || nKeyCode == asciiRightArrow)){ bRet = false; } if(!bRet){ try{ oEvent.returnValue = false; oEvent.cancelBubble = true; if(document.all){ oEvent.keyCode = 0; }else{ oEvent.preventDefault(); oEvent.stopPropagation(); } alert(msg); }catch(ex){ alert(msg); } } return bRet; }Mas tem um Porem, o alt, no IE tah completamente Bloqueado, tem como fazer ficar soh o alt e as setas? Pq como é pra chat, se o cara quer digitar caracteres especiais não vai conseguir....Obrigado Thiago....Bom, já consegui desativar o F5, desativar avançar e voltar com o ALT, e detectar o refresh do teclado e o back button do teclado, agora resta anular o refresh do teclado e o voltar.dah uma olhadinha aew thiago, ou alguem que puder me ajudar, pois apenas detecta mas não anula... var msg = 'Função desativada!'; //ESSAS SERÃO AS TECLAS DESABILITADAS var asciiF5 = 116; var asciiALT = 18; var asciiLeftArrow = 37; var asciiRightArrow = 39; var asciirefresh = 168; var asciiback1 = 166; if(document.all){ //ie has to block in the key down document.onkeydown = onKeyPress; }else if (document.layers || document.getElementById){ //NS and mozilla have to block in the key press document.onkeypress = onKeyPress; } function onKeyPress(evt) { window.status = ''; var oEvent = (window.event) ? window.event : evt; var nKeyCode = oEvent.keyCode ? oEvent.keyCode : oEvent.which ? oEvent.which : void 0; var bIsFunctionKey = false; if(oEvent.charCode == null || oEvent.charCode == 0){ f5button = (nKeyCode == asciiF5) } if(oEvent.charCode == null || oEvent.charCode == 0){ refreshbutton = (nKeyCode == asciirefresh) } if(oEvent.charCode == null || oEvent.charCode == 0){ backbutton = (nKeyCode == asciiback1) } var sChar = String.fromCharCode(nKeyCode).toUpperCase(); var oTarget = (oEvent.target) ? oEvent.target : oEvent.srcElement; var sTag = oTarget.tagName.toLowerCase(); var sTagType = oTarget.getAttribute("type"); var bAltPressed = (oEvent.altKey) ? oEvent.altKey : oEvent.modifiers & 1 > 0; var bRet = true; if(sTagType != null){sTagType = sTagType.toLowerCase();} if(f5button){ bRet = false; } // botão refresh do teclado else if(refreshbutton){ bRet = false; } // botão voltar do teclado else if(backbutton){ bRet = false; } else if(bAltPressed && (nKeyCode == asciiLeftArrow || nKeyCode == asciiRightArrow)){ bRet = false; } if(!bRet){ try{ oEvent.returnValue = false; oEvent.cancelBubble = true; if(document.all){ oEvent.keyCode = 0; }else{ oEvent.preventDefault(); oEvent.stopPropagation(); } alert(msg); }catch(ex){ alert(msg); } } return bRet; }// - Desabilita o Botão direito do mousefunction desabilitar(){ return false}document.oncontextmenu=desabilitarNão to falando daquelas teclinas de atalho.... e por falar nisso o back space fora do text tb volta.... preciso pensar nisso tb...
>
Não to falando daquelas teclinas de atalho.... e por falar nisso o back space fora do text tb volta.... preciso pensar nisso tb...
Não sei que teclas de atalho são essas não. Acho que meu teclado não tem isso, então.Só uma coisa: lembre-se que a pessoa pode atualizar através do mouse e que também pode desabilitar o javascript.
Sabe aqueles teclados multimedia?, são estas teclas, o mouse tah aki a solução:// - Desabilita o Botão direito do mousefunction desabilitar(){ return false}document.oncontextmenu=desabilitare quanto a desabilitar o javascript, precisaria da barra de ferramentas, que no caso já foi removida por um pop-up...sei que se o cara quizer realmente, atualizar a página, vai achar um meio, mas to tentando evitar acidentes...é que no caso, se ele der o refresh, vai sair e entrar no chat, e ainda vai abrir a janela de login, que neste caso acaba com as sessions do cara.Para o sistema não tem problema, pois as session são novamente gravadas, mas é incoviniente, o malandro ficar mandando mesagens "entrei" e" sai" toda a vez que apertar o F5, ou der o refresh.
ve se te ajuda:
http://forum.imasters.com.br/index.php?showtopic=164971