Foros del Web » Programando para Internet » Javascript »

Función para evitar teclas F5,F11,Backspace(excepto formularios)

Estas en el tema de Función para evitar teclas F5,F11,Backspace(excepto formularios) en el foro de Javascript en Foros del Web. 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 ...
  #1 (permalink)  
Antiguo 08/02/2006, 13:52
Avatar de sabandija25  
Fecha de Ingreso: abril-2004
Mensajes: 302
Antigüedad: 20 años
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
  #2 (permalink)  
Antiguo 09/02/2006, 06:09
Avatar de mveraa  
Fecha de Ingreso: diciembre-2002
Ubicación: santiago-chilito
Mensajes: 1.931
Antigüedad: 21 años, 4 meses
Puntos: 2
hola sabandija25 justo necesito implementar el bloque de f5 pero no entiendo mucho el javascrpt me podrias dar una mano , porque no me funciona.

puse el codigo asi:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>


<script language="JavaScript" type="text/javascript"><!--


function winopen(url, parameters)
{
myref = window.open(url,'new',parameters);
myref.focus();
}
// -->

//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')=='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
{ document.activeElement.value.keyCode = 8; } //Realiza el backspace.
}
}
}
}
//end desabilitar teclas
</script>


<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><style type="text/css">
<!--
body {
background-image: url(../seguimientos2/fotos/logo_muni.gif);
}
-->
</style></head>

<body style="padding: 0; margin: 0;" topmargin="0" rightmargin="0" bottommargin="0" leftmargin="0" marginheight="0" marginwidth="0" bgcolor="FFFFFF">

<table width="100%" height="100%" cellpadding="0" cellspacing="0" border="0"><tr><td valign="middle" align="center">
<table width="929" cellpadding="0" cellspacing="0" border="0">
<tr><td>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="924" height="540">
<param name="movie" value="../seguimientos2/swf/inicio.swf" />
<param name="quality" value="high" />
<param name="wmode" value="transparent" />
<embed src="../seguimientos2/swf/inicio.swf" width="924" height="540" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent"></embed>
</object>



</td></tr>
<tr>
<td style="color: 666666; font-size: 9px; font-family: arial, helvetica, sans-serif; padding-top: 5px;">
<img src="../seguimientos/fotos/Santiago_Escudo.gif" alt="" width="30" height="27" align="left" style="float: left; margin: 4px 10px 10px 0;" />SITIO WEB DESARROLLO EN MACROMEDIA FLASH , RESOLUCION OPTIMA 1024X768.
</td>
</tr></table>
</td></tr></table>
</body>
</html>
¿enque me puedo esta equivocando?
un saludo.
__________________
"Cuando se adelanta un oponente, enfréntalo y salúdalo; si intenta retroceder, déjalo seguir su camino"

Última edición por mveraa; 09/02/2006 a las 06:43
  #3 (permalink)  
Antiguo 19/11/2008, 11:31
 
Fecha de Ingreso: noviembre-2007
Ubicación: Trabajo en INEGI
Mensajes: 33
Antigüedad: 16 años, 5 meses
Puntos: 0
De acuerdo 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...
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta

SíEste tema le ha gustado a 1 personas (incluyéndote)




La zona horaria es GMT -6. Ahora son las 17:30.