¿Cómo puedo hacer que la altura de un iframe se ajuste al contenido que contiene? Supongo que calcularía la diferencia entre la altura del contenido y la altura del cuadro flotante (algo que no sé cómo hacer) y lo usaría con un ciclo while para incrementar una variable para usarla como una altura, pero no puedo ajustar mi mira cómo hacer estas cosas en realidad. Antes de preguntar: sí, el contenido en el marco es de mi sitio. No entre dominios.make iframe height fit content
Respuesta
No estoy seguro de por qué desea utilizar un iframe y no un div dinámico lleno, por ejemplo, a través de AJAX, pero:
poner el contenido dentro del marco flotante en un div, a continuación, obtener la altura de la div. Me gustaría sugerir el uso de jQuery, así:
$("#divId").height();
Pero si no se puede utilizar jQuery, usted debería ser capaz de utilizar este:
document.getElementById("divId").offsetHeight;
Entonces que había necesidad de ajustar la altura del iframe a lo que sea que tengas
jquery:
$("#iframeId").height($("#divId").height());
js regulares:
document.getElementById("iframeId").style.height =
document.getElementById("divId").offsetHeight;
esto no funciona. No puede acceder al div del iframe desde fuera del iframe –
Sin embargo, puede hacer esto: 'document.getElementById (" frameId "). ContentWindow.document.getElementById (" id ")' – JCOC611
@ JCOC611 'document.getElementById ("frameId"). contentWindow.document' tiene prohibido el acceso en estos días, también, hasta donde puedo ver (al menos en FF) – YakovL
<iframe id="moo" src="something.html"><iframe>
<script>
function onContentChange(){
var NewSize=$('moo').getScrollSize();
$('moo').setStyles({
width: NewSize.x,
height: NewSize.y
});
}
</script>
y dentro del somthing.html, en el fondo o proceso de carga hacen algo en las líneas de
window.parent.window.onContentChange()
Debe ser '' '$ ('# moo')' '' Si esto se supone que es una llamada jquery ... – Guntram
Cuando lo escribí, era un chico mootools. –
Renderizar dinámicamente el iframe en javasc ript una vez que el elemento contenedor ("td1") ha sido dibujado.
<script type="text/javascript">
var iframesrc = "@Href("~/about")";
function init() {
var vHeight = document.getElementById("td1").offsetHeight;
document.getElementById("td1").innerHTML="<iframe style=\"width:100%; height:" + vHeight + "px\" src=\"" + iframesrc + "\"></iframe>";
}
window.onload = init;
</script>
...
<td id="td1" style="width: 100%; height:100%;">
</td>
he aquí una solución usando jQuery:
$('#iframe').height($('#iframe').contents().find('body').height());
- 1. Lectura de Iframe Content en Iframe Load
- 2. Fancybox height no escuchará
- 3. GridView auto fit images
- 4. ¿Por qué Fit/FitNesse?
- 5. javascript window.location iframe, make parent window ir a la ubicación
- 6. Algoritmo de programación Best Fit
- 7. 100% div height
- 8. using fancybox set height and width
- 9. jQuery height() no cambia el tamaño
- 10. Altura de ventana visible en lugar de $ (ventana) .height();
- 11. html table fixed height?
- 12. jQuery Equal Height Divs
- 13. editfield weird height
- 14. getHeight() vs getLayoutParams(). Height
- 15. Javascript - Get Image height
- 16. line-height sin unidades
- 17. jQuery css min-height
- 18. IE6 min-height dilema
- 19. Cómo cerrar iframe desde dentro de iframe?
- 20. Formato de datos de Wii Fit?
- 21. Loess Fit y la ecuación resultante
- 22. ¿Contenido del centro div y fit?
- 23. fit dataGridView size to row's and columns's total size
- 24. Fancybox.close() en un iframe
- 25. ItemsControl, VirtualizingStackPanel y ScrollViewer height
- 26. tableView cell height ... ¿cómo personalizarlo?
- 27. CSS max-height no funciona
- 28. Establecer max-height usando javascript
- 29. jQuery height() devuelve valores falsos
- 30. DialogFragment set height of Dialog
¿Alguien todavía utilizan marcos? – yoda
@yoda quiso decir iframe, y solo las usan compañías insignificantes en la esfera web como Google y Facebook. –
el contenido enmarcado está en su sitio? – Trufa