动态iframe高度与css或jquery

时间:2014-02-05 10:35:57

标签: javascript jquery html css

我正在使用jquery动态创建iframe,iframe的高度太大,我想为此iframe设置自动高度。加载数据后,iframe应自动调整,我试图在点击事件中实现这一点

注意:我是动态创建的,因此页面中有多个iframe。

 $( ".deletephoto" ).live('click',function (event){
 event.preventDefault();
 if (confirm("Are you sure you want to delete this photo?")) {
   var iframediv=$(this).parent().find('#ifarmediv');
   $(iframediv).html("<iframe src='../users/upload' id='the_iframe' class='iframephotoedit'></iframe>");

   var   currentiframe=$(this).parent().find('#ifarmediv').find('iframe');
    $(currentiframe).load(function() {
                      $(this).height( $(this).contents().find("body").height() );
                    }); 

});

1 个答案:

答案 0 :(得分:1)

更改其负载上iframe的高度:

$("#the_iframe").load(function() {
  $(this).height( $(this).contents().find("body").height() );
}); 

<强> Demo