![Antiguo](http://static.forosdelweb.com/fdwtheme/images/statusicon/post_old.gif)
19/11/2008, 11:31
|
| | Fecha de Ingreso: noviembre-2007 Ubicación: Trabajo en INEGI
Mensajes: 33
Antigüedad: 17 años, 2 meses Puntos: 0 | |
Respuesta: Función para evitar teclas F5,F11,Backspace(excepto formularios) Excelente codigo que nos proporciono sabandija25
Envio la implementacion que hice
<body onkeydown="validaTecla()">
function validaTecla() {
if (!valida()) {
if (navigator.appName == 'Microsoft Internet Explorer')
window.event.keyCode = 0;
else
e.which = 0;
}
}
function valida() {
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')=='sel ect-one')
{ return false; } //Evita Back en select.
if (document.activeElement.getAttribute('type')=='but ton')
{ return false; } //Evita Back en button.
if (document.activeElement.getAttribute('type')=='rad io')
{ return false; } //Evita Back en radio.
if (document.activeElement.getAttribute('type')=='che ckbox')
{ return false; } //Evita Back en checkbox.
if (document.activeElement.getAttribute('type')=='fil e')
{ return false; } //Evita Back en file.
if (document.activeElement.getAttribute('type')=='res et')
{ return false; } //Evita Back en reset.
if (document.activeElement.getAttribute('type')=='sub mit')
{ 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
{ return true; } //Realiza el backspace.
}
}
}
}
posteriormente asigno a los input o textbox la funcion
function Fue_enter(obj, objAnt, objSig) {
if (navigator.appName == 'Microsoft Internet Explorer')
window.event.keyCode = (window.event.keyCode == 13 ) ? 9 : window.event.keyCode;
else
e.which = (e.which == 13 ) ? 9 : e.which;
codigo = (navigator.appName == 'Microsoft Internet Explorer') ? window.event.keyCode : e.which;
if (codigo == 9) document.getElementById(obj).focus(); // Enter o Tab
if (codigo == 38) document.getElementById(objAnt).focus(); // Flecha arriba
if (codigo == 40) document.getElementById(objSig).focus(); // Flecha abajo
}
en su evento onkeydown
Gracias por la aportacion sabandija25... |