设置iFrame的高度

Setting height to an iFrame

本文关键字:高度 iFrame 设置      更新时间:2023-09-26

我试过这个:

$('#my_ifr').css('height', '5px !important');

这个:

$('#my_ifr').height(5);

但大小保持不变。当我写:

$('#my_ifr').height();

在cosole中,我得到5,但当我检查Goog 中的元素时

检查一下,它工作正常。。。

$('#iframeID').css({'height':'500px'});

http://jsfiddle.net/smanimani/GwkRQ/98/

但是,你想增加连续高度意味着,

你这样用,

tinyMCE.init({
...
height : "500"
});

您必须设置他的height属性

$('#my_ifr').attr('height', '5');

这很好

$('#my_ifr').css('height', '500');

两个答案(@yogi&@Mihai Iorga)都是正确的,但看起来像你的小提琴。。。。有几点需要评论:

您没有触发函数。。。添加:

$(function() {
 // Handler for .ready() called.
});

$(document).ready(function() {
  // Handler for .ready() called.
});

(是一样的…)

现在。。。另一件事是,在你的jsfiddle中,没有iframe#my_ifr


尝试此更新:http://jsfiddle.net/GwkRQ/94/

$(function() {
    // Not Valid
    //$('#mce_0_ifr').height(5);
    // Valid - by @yogi
    $('#my_ifr').css('height', '500');
    // Valid - by @Mihai Iorga only if no attr was previulsy set
    // but be carefull because pre-defined element.style or css rule
    // will overright the atribute (attr)
    $('#my_ifr').attr('height', '5');
    // That is, the iframe will have 500 and not 5
});​
function checkifloaded () {
    if ($('#mce_0_ifr').length > 0) {
        $('#mce_0_ifr').css({'height': '5px'});
        window.clearInterval(intid);
    }
}
var intid = setInterval(checkifloaded, 500);

http://jsfiddle.net/GwkRQ/163/

嘿,在设置css高度属性之前,您需要加载Iframe的内容。否则,它将保持未定义状态,并且不能更改height属性。。

WOrking代码

setInterval(function(){if(typeof($('#mce_0_ifr').css('height'))=='undefined'){}else{$('#mce_0_ifr').css('height','50px');}},0);

FIDLLE工作演示