Necesitas actualizar Flash player
Foro de posicionamiento en buscadores
 
 AyudaAyuda   BuscarBuscar   RegístreseRegístrese   ConectarseConectarse

Sindicar RSS Sindicar Atom
How to dynamically adjust an iframe's height
Traducir: Traducir a Español
Publicar Nuevo Tema   Responder al Tema    Índice del Foro SeoPosicion -> Noticias en ingles
Ver tema anterior :: Ver siguiente tema  
Autor Mensaje
Noticias RSS
Elite
Elite


Registrado: 20 Ago 2006
Mensajes: 2287


MensajePublicado: 14 Ene Lun, 2008 10:00 AM    Título del mensaje: How to dynamically adjust an iframe's height Responder citando

How to dynamically adjust an iframe's height

Suppose you want to include a child iframe on your page. You'd like to resize the height of the child iframe so that it doesn't show a scrollbar. That is, you want something that looks like this:



Here's one way you can do it. First, make the iframe that you want to include. I made a file "child-frame.html" that looks like this:

Cita:


<html>

<head> <title>Child frame</title> </head>

<body bgcolor="#000000″>

<font color="#ffffff">

<p>Child frame.</p>

<p>Child frame.</p>

<p>Child frame.</p>

<p>Child frame.</p>

<p>Child frame.</p>

<p>Child frame.</p>

<p>Child frame.</p>

<p>Child frame.</p>

</font>

</body>

</html>



Now in the parent frame, you can make code like this:

Cita:


<html>

<head> <title>Parent frame</title> </head>

<body onload="resizeFrame(document.getElementById('childframe'))" bgcolor="#cccccc">

<script type="text/javascript">

// Firefox worked fine. Internet Explorer shows scrollbar because of frameborder

function resizeFrame(f) {

f.style.height = f.contentWindow.document.body.scrollHeight + "px";

}

</script>

<p>Parent frame.</p>

<p>Parent frame.</p>

<p>Parent frame.</p>

<p>Parent frame.</p>

<p>

<iframe frameborder=0 border=0 src="./child-frame.html" name="childframe" id="childframe">

</iframe>

</p>

</body>

</html>



You can also see a live example of resizing an iframe height dynamically.

What does this code do? When the body of the parent frame loads, it looks up the document element "childframe" which corresponds to the iframe. Then the page calls a function resizeFrame(). The function sets the height of the frame to be the scrollHeight, which effectively removes the scrollbar.

The only tricky bit is the "frameborder=0 border=0″ attributes on the frame. If you leave off the frameborder attribute, Internet Explorer will assume that the frame should have a nonzero border, but it won't include the frame border in the value it returns for scrollHeight. The net effect is that IE will show a scrollbar unless you add "frameborder=0″.

It always annoys me to dive into cross-browser development when it feels like things should be standardized. Looks like it annoys other people too.

Anyway, feel free to rip on my code in the comments, but I was looking for a simple, working example of setting an iframe's height so that the iframe wouldn't have a scrollbar.

[img]http://feeds.mattcutts.com/~r/mattcutts/uJBW/~4/216263462[/img]
Fuente
Volver arriba
Mostrar mensajes anteriores:   
Publicar Nuevo Tema   Responder al Tema    Índice del Foro SeoPosicion -> Noticias en ingles Noticias en ingles Todas las horas están en GMT + 1 Hora
Página 1 de 1



Foro proporcionado por phpBB ©
diseño web, posicionamiento en buscadores y alojamiento web.
Inicio de diseño Web y posicionamiento Web Diseño Web Posicionamiento en buscadores y optimización Web Alojamiento Web y hosting Foro de posicionamiento Web y buscadores Directorio SeoPosicion Formulario de contacto

Copyright (c) 2006. SeoPosicion©. Todos los derechos reservados.