Me van a disculpar por hacer esta consulta pero tengo, para variar, un lío entre manos y ya de rabia no puedo avanzar ni retroceder. Verán, tengo este código que me permite bloquear varias teclas:
Cita:
Pero funciona para IE ya que utiliza el window.event.keyCode. Investigando encontré información que me indica que debería de hacer algo como //Inicio desabilitar teclas
var controlprecionado = 0;
var altprecionado = 0;
function desactivarCrlAlt(teclaactual)
{
var desactivar = false;
//Ctrl +
if (controlprecionado==17)
{
if (teclaactual==78 || teclaactual==85 ) //Ctrl+N y Ctrl+U deshabilitado
{desactivar=true;}
if (teclaactual==82) //Ctrl+R deshabilitado
{desactivar=true;}
if (teclaactual==116) //Ctrl+F5 deshabilitado
{desactivar=true;}
if (teclaactual==114) //Ctrl+F3 deshabilitado
{desactivar=true;}
}
//Alt +
if (altprecionado==18)
{
if (teclaactual==37) //alert("Alt+ [<-] deshabilitado");
{desactivar=true;}
if (teclaactual==39) //alert("Alt+ [->] deshabilitado");
{desactivar=true;}
}
if (teclaactual==17)controlprecionado=teclaactual;
if (teclaactual==18)altprecionado=teclaactual;
return desactivar;
}
document.onkeyup = function()
{
if (window.event && window.event.keyCode==17)
{controlprecionado = 0;}
if (window.event && window.event.keyCode==18)
{altprecionado = 0;}
}
document.onkeydown = function()
{
//114 -> F3 116 -> F5 117 -> F6 122 -> F11
if (window.event && desactivarCrlAlt(window.event.keyCode))
{return false;}
if (window.event && (window.event.keyCode == 114 || window.event.keyCode == 116 || window.event.keyCode == 117 || window.event.keyCode == 122))
{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) //Evita Back en página.
{return false;}
else
{
if (document.activeElement.getAttribute('type')=='sel ect-one') //Evita Back en select.
{return false;}
if (document.activeElement.getAttribute('type')=='but ton') //Evita Back en button.
{return false;}
if (document.activeElement.getAttribute('type')=='rad io') //Evita Back en radio.
{return false;}
if (document.activeElement.getAttribute('type')=='che ckbox') //Evita Back en checkbox.
{return false;}
if (document.activeElement.getAttribute('type')=='fil e') //Evita Back en file.
{return false;}
if (document.activeElement.getAttribute('type')=='res et') //Evita Back en reset.
{return false;}
if (document.activeElement.getAttribute('type')=='sub mit') //Evita Back en submit.
{return false;}
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.
}
}
}
}
var controlprecionado = 0;
var altprecionado = 0;
function desactivarCrlAlt(teclaactual)
{
var desactivar = false;
//Ctrl +
if (controlprecionado==17)
{
if (teclaactual==78 || teclaactual==85 ) //Ctrl+N y Ctrl+U deshabilitado
{desactivar=true;}
if (teclaactual==82) //Ctrl+R deshabilitado
{desactivar=true;}
if (teclaactual==116) //Ctrl+F5 deshabilitado
{desactivar=true;}
if (teclaactual==114) //Ctrl+F3 deshabilitado
{desactivar=true;}
}
//Alt +
if (altprecionado==18)
{
if (teclaactual==37) //alert("Alt+ [<-] deshabilitado");
{desactivar=true;}
if (teclaactual==39) //alert("Alt+ [->] deshabilitado");
{desactivar=true;}
}
if (teclaactual==17)controlprecionado=teclaactual;
if (teclaactual==18)altprecionado=teclaactual;
return desactivar;
}
document.onkeyup = function()
{
if (window.event && window.event.keyCode==17)
{controlprecionado = 0;}
if (window.event && window.event.keyCode==18)
{altprecionado = 0;}
}
document.onkeydown = function()
{
//114 -> F3 116 -> F5 117 -> F6 122 -> F11
if (window.event && desactivarCrlAlt(window.event.keyCode))
{return false;}
if (window.event && (window.event.keyCode == 114 || window.event.keyCode == 116 || window.event.keyCode == 117 || window.event.keyCode == 122))
{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) //Evita Back en página.
{return false;}
else
{
if (document.activeElement.getAttribute('type')=='sel ect-one') //Evita Back en select.
{return false;}
if (document.activeElement.getAttribute('type')=='but ton') //Evita Back en button.
{return false;}
if (document.activeElement.getAttribute('type')=='rad io') //Evita Back en radio.
{return false;}
if (document.activeElement.getAttribute('type')=='che ckbox') //Evita Back en checkbox.
{return false;}
if (document.activeElement.getAttribute('type')=='fil e') //Evita Back en file.
{return false;}
if (document.activeElement.getAttribute('type')=='res et') //Evita Back en reset.
{return false;}
if (document.activeElement.getAttribute('type')=='sub mit') //Evita Back en submit.
{return false;}
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.
}
}
}
}
Cita:
pero resulta que probé reemplazando por todos los windowevent.keyCode y no logró que funcione ni para IE ni para FF. Sólo cuando regreso al código original es que logro que funciona para IE pero evidentemente no para FF.variable = (document.all) ? e.keyCode : e.which;
¿Que debo cambiar en este código para que funcione tanto para IE como para FF?.
Gracias por el apoyo, en verdad no ato ni desato.
Un saludo desde el Perú