Ver Mensaje Individual
  #6 (permalink)  
Antiguo 04/03/2008, 15:49
Avatar de derkenuke
derkenuke
Colaborador
 
Fecha de Ingreso: octubre-2003
Ubicación: self.location.href
Mensajes: 2.665
Antigüedad: 20 años, 6 meses
Puntos: 45
Re: Disparar un evento asignado con Event.observe

Hola arathael y Panino:

He buscado, y aunque me ha costado encontrarlo bastante he dado más o menos con lo que se pide en el primer post:

Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<
title>test</title>


<
script>
function 
addEvent(objevTypefnuseCapture){
 
 if (
obj.addEventListener){
    
obj.addEventListener(evTypefnuseCapture);
    
  } else if (
obj.attachEvent){
    
obj.attachEvent("on"+evTypefn);
   
  } else {
   
obj['on'+evType]=fn;
  }
}
function 
hablar(e) { 
    
// Lo único que hago es tener una lista de propiedades, y si el objeto e posee las propiedades de la lista se alertan.
    
var ''wantedprops=',type,target,currentTarget,bubbles,cancelable,windowObject,detail,screenX,screenY,clientX,clientY,ctrlKey,altKey,shiftKey,metaKey,button,relatedTarget,';
    for(
p in e) {
        if(
wantedprops.indexOf(','+p+',')+1) {
            
s+='\n'+p+': '+((typeof(e[p])=='object')?'The \"A\" element':e[p]);
        }
    }
    
alert('Event fired:\n'+s+'\nThere may be more, but I have not included all of it.'); 
}


window.onload=function() {
    
// Coloco el evento click
    
addEvent(document.getElementById('pp'), 'click'hablarfalse);
    
// Lo lanzo forzosamente
    
if( document.fireEvent ) {                            // IE
        
document.getElementById('pp').fireEvent("onclick");
    }
    else if( 
document.dispatchEvent ) {                    // estándar
        
var evObj document.createEvent('MouseEvents');                                // creamos el evento de tipo MouseEvents
        
evObj.initMouseEvent'click'truetruewindow1123457220falsefalsetruefalse0null );    // le damos características
        
document.getElementById('pp').dispatchEvent(evObj); 
    }
    else
        
alert("No puedo lanzar evento");
}
</script>


</head>

<body>
<div id="pp">click</div>
</body>
</html> 
Ésto yo no lo conocía (tampoco he tenido que usarlo). Está sacado de aqui. Es un sitio interesantillo, cuenta bastantes cosas nuevas para mi.


Bueno, ahí está mi aporte, y funciona en IE y FF.


Un saludo
__________________
- Haz preguntas inteligentes, y obtendrás más y mejores respuestas.
- Antes de postearlo Inténtalo y Búscalo.
- Escribe correctamente tus mensajes.