简体   繁体   English

iframe的动态高度

[英]Dynamic height of iframe

I am currently working on an existing site that uses iframes(sigh!), these are pretty painful to work with and I'm having problems getting the height of the iframe to scale with the height of the HTML content. 我目前正在使用一个使用iframe的现有网站(叹息!),这些都非常难以使用,我在使用HTML内容的高度来扩展iframe的高度时遇到了问题。

I've tried a few different script snippets that floats around on the interwebs, but none of them have worked for me. 我已经尝试了几个不同的脚本片段,它们漂浮在互联网上,但它们都没有为我工作。 I really want to use jQuery to do this, but that's not an option because IT wants to keep the size of the pageload down. 我真的想用jQuery来做这件事,但这不是一个选择,因为IT希望减少页面加载的大小。

Does anyone know of good way to do this, in a way that works on both FF and IE 6+? 有没有人知道这样做的好方法,以适用于FF和IE 6+的方式?

You should just be able to simply set the height and the width parameters - since these are both valid attributes of the iframe dom element. 您应该只需设置高度和宽度参数 - 因为这些都是iframe dom元素的有效属性。

function resize(width, height) {
  var frame = document.getElementById('my_iframe');
  frame.width = width;
  frame.height = height;
}

Of course, this only applies if you are attempting to resize the iframe from it's parent element (the document with the actual iframe tag). 当然,这仅适用于您尝试从其父元素(具有实际iframe标记的文档)调整iframe的大小。 If you are trying to resize the iframe from within the iframe (the document the iframe loads) you will need to call a public function of the parent element to perform the resize. 如果您尝试从iframe(iframe加载的文档)中调整iframe大小,则需要调用父元素的公共函数来执行调整大小。

In iframe: parent.resize(600, 800); 在iframe中: parent.resize(600, 800);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM