Foros del Web » Creando para Internet » HTML »

Obtener valor desde un iframe

Estas en el tema de Obtener valor desde un iframe en el foro de HTML en Foros del Web. Hola que tal!!. Se puede extraer un valor desde un iframe? Explico: Tengo esta pagina: Código HTML: <html> <head> <script language= "JavaScript" type= "text/javascript" > ...
  #1 (permalink)  
Antiguo 20/12/2005, 10:16
 
Fecha de Ingreso: julio-2005
Ubicación: Mexico
Mensajes: 140
Antigüedad: 18 años, 9 meses
Puntos: 0
Obtener valor desde un iframe

Hola que tal!!.

Se puede extraer un valor desde un iframe? Explico:
Tengo esta pagina:

Código HTML:
<html>
<head>
<script language="JavaScript" type="text/javascript">
  function ver(){
    var oFrame = document.getElementById('cat');
    alert(oFrame.document.getElementById('dato').value);
  }
</script>
</head>

<body>
<form id="forma">

    <iframe src="contenido.php" id="cat" width="100%"></iframe>
    <input type="button" value="ver" onclick="return ver()">  

</form>
</body>
</html> 
El contenido del iframe es este:

Código HTML:
<html>
<body>
<form id="forma">
 
  <input type="hidden" id="dato" value="Hola mundo!!">
 
</form>
</body>
</html> 
Y al pincharle no me muestra nada
¿Si se puede hacer algo smejante?
__________________
SELECT * FROM LA_VIDA
  #2 (permalink)  
Antiguo 20/12/2005, 10:22
 
Fecha de Ingreso: julio-2005
Ubicación: Mexico
Mensajes: 140
Antigüedad: 18 años, 9 meses
Puntos: 0
Suscribiendome ja ja
__________________
SELECT * FROM LA_VIDA
  #3 (permalink)  
Antiguo 20/12/2005, 10:22
Avatar de JavierB
Colaborador
 
Fecha de Ingreso: febrero-2002
Ubicación: Madrid
Mensajes: 25.052
Antigüedad: 22 años, 2 meses
Puntos: 772
Hola ane_aaron

Pon así el iframe:

<iframe src="contenido.php" name="cat" id="cat" width="100%"></iframe>

y así la función:

function ver(){
alert(cat.document.getElementById('dato').value);
}

Espero que te sirva. Saludos,
  #4 (permalink)  
Antiguo 20/12/2005, 10:30
 
Fecha de Ingreso: julio-2005
Ubicación: Mexico
Mensajes: 140
Antigüedad: 18 años, 9 meses
Puntos: 0
Ya funciona.

Gracias jabierB. Dos dudas,
1. ¿Que tan portable es esta solucion?

2. Acabo de investigar una alternativa para el iframe, es el OVERFLOAT en un DIV

Código HTML:
<div style="HEIGHT:100px; WIDTH:50%; OVERFLOW:auto">

  <table border=1 width=100%>
        <tr><td>stuff</td>
        <td>more stuff</td></tr>
        <tr><td>stuff</td>
        <td>more stuff</td></tr>
        <tr><td>stuff</td>
        <td>more stuff</td></tr>
        <tr><td>stuff</td>
        <td>more stuff</td></tr>
        <tr><td>stuff</td>
        <td>more stuff</td></tr>
        <tr><td>stuff</td>
        <td>more stuff</td></tr>
        <tr><td>stuff</td>
        <td>more stuff</td></tr>    
       <tr><td>stuff</td>
        <td>more stuff</td></tr>
  </table>
</div> 
¿Sabes algo sobre el manejo de esto?
__________________
SELECT * FROM LA_VIDA
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 03:05.