Foros del Web » Programando para Internet » Javascript »

Control de clicks en Iframe

Estas en el tema de Control de clicks en Iframe en el foro de Javascript en Foros del Web. Hola: Tengo el siguiente problema que a continuación os detallo. Quiero controlar cuando alguna persona haga click en un iframe. El codigo que tengo es ...
  #1 (permalink)  
Antiguo 12/05/2009, 02:01
 
Fecha de Ingreso: octubre-2003
Mensajes: 364
Antigüedad: 20 años, 6 meses
Puntos: 1
Control de clicks en Iframe

Hola:
Tengo el siguiente problema que a continuación os detallo.

Quiero controlar cuando alguna persona haga click en un iframe.

El codigo que tengo es el siguiente:

<iframe src='xxx_pagina' width='300' height='250' frameborder='0' scrolling='no' marginheight='0' marginwidth='0' id="theiframe" name="theiframe" onload="iframeclick()"></iframe>

Cuando pinto el iframe declaro la funcion iframeclick() que realiza lo siguiente:

function iframeclick() {
document.getElementById("theiframe").contentWindow .document.onmousedown = function() {
alert("Funciona");
}

}

Esto funciona bien... pero si dentro del iframe se carga otro iframe (Esto puede ser posible por diferentes motivos) entonces deja de funcionar el control de clicks.

Cómo puedo hacer para que el evento onmousedown se siga manteniendo.

Un saludo y espero que alguien me pueda ayudar.
  #2 (permalink)  
Antiguo 12/05/2009, 05:42
Colaborador
 
Fecha de Ingreso: marzo-2008
Ubicación: Sabadell
Mensajes: 4.897
Antigüedad: 16 años, 1 mes
Puntos: 574
Respuesta: Control de clicks en Iframe

Archivo principal

Código HTML:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Documento sin t&iacute;tulo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="javascript">
function iframeclick(obj) {
obj.contentWindow .document.onmousedown = function() {
alert("Funciona " + obj.src);
}
} 
</script>
</script>
</head>

<body>
Primer<br>
<iframe src="iframes.htm" width='300' height='250' frameborder='0' scrolling='no' marginheight='0' marginwidth='0' id="theiframe" name="theiframe" onload="iframeclick(this)"></iframe>
</body>
</html> 
Dos alternativas para el iframes.htm (archivo que se carga en el primer iframe)

Código HTML:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Documento sin t&iacute;tulo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="javascript">
function iframeclick(obj) {
obj.contentWindow .document.onmousedown = function() {
alert("Funciona " + obj.src);
}
} 
</script>
</head>

<body>
Segon<br>
<iframe src="capas.htm" width='300' height='250' frameborder='0' scrolling='no' marginheight='0' marginwidth='0' id="theiframe" name="theiframe" onload="iframeclick(this)"></iframe>
</body>
</html> 
Código HTML:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Documento sin t&iacute;tulo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
Segon<br>
<iframe src="xxx_pagina" width='300' height='250' frameborder='0' scrolling='no' marginheight='0' marginwidth='0' id="theiframe" name="theiframe" onload="parent.iframeclick(this)"></iframe>
</body>
</html> 
Te sirve?

Es decir o repites la funcion o usas "parent." para referirte a la funcion del primer archivo....

Quim
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




La zona horaria es GMT -6. Ahora son las 13:41.