Ver Mensaje Individual
  #1 (permalink)  
Antiguo 08/02/2006, 13:52
Avatar de sabandija25
sabandija25
 
Fecha de Ingreso: abril-2004
Mensajes: 302
Antigüedad: 20 años, 9 meses
Puntos: 0
Mensaje Función para evitar teclas F5,F11,Backspace(excepto formularios)

Buenas...

Estuve revisando las faq y combiné el método que sale para evitar las teclas F5 y F11 con un script chiquito que tengo para evitar que con la tecla backspace(la flechita) nos tire a la página anterior, sin afectar el correcto funcionamiento de los formularios cuando presionamos un backspace.

Acá les va el código, espero que les sirva...
PD: Si alguien quiere aportar alguna otra tecla por ejemplo la del botón derecho, crtl bienvenido...

Código PHP:
<script>
//begin desabilitar teclas
document.onkeydown = function(){ 
//116->f5
//122->f11
if (window.event && (window.event.keyCode == 122 || window.event.keyCode == 116)){
window.event.keyCode 505
}

if (
window.event.keyCode == 505){ 
return 
false


if (
window.event && (window.event.keyCode == 8))
{
valor document.activeElement.value;
if (
valor==undefined) { return false; } //Evita Back en página.
else
{
if (
document.activeElement.getAttribute('type')=='select-one')
    { return 
false; } //Evita Back en select.
if (document.activeElement.getAttribute('type')=='button')
    { return 
false; } //Evita Back en button.
if (document.activeElement.getAttribute('type')=='radio')
    { return 
false; } //Evita Back en radio.
if (document.activeElement.getAttribute('type')=='checkbox')
    { return 
false; } //Evita Back en checkbox.
if (document.activeElement.getAttribute('type')=='file')
    { return 
false; } //Evita Back en file.
if (document.activeElement.getAttribute('type')=='reset')
    { return 
false; } //Evita Back en reset.
if (document.activeElement.getAttribute('type')=='submit')
    { return 
false; } //Evita Back en submit.
else //Text, textarea o password
{
    if (
document.activeElement.value.length==0)
        { return 
false; } //No realiza el backspace(largo igual a 0).
    
else
        { 
document.activeElement.value.keyCode 8; } //Realiza el backspace.
}
}
}
}
//end desabilitar teclas
</script> 
Ésto lo pueden colocar en un include. Saludos