1
function setHeight() {
    var iframes = parent.document.getElementsByClassName('targetIframe');
    for(var i = 0; i < iframes.length; i++)
    iframes[i].height = document['body'].offsetHeight;
}

A variation of this answer.

It's using the getElementsByClassName function,which is not supported by IE.

How to rewrite it with jQuery?

Community
  • 1
  • 1
ollydbg
  • 3,475
  • 7
  • 28
  • 29

3 Answers3

1
function setHeight() {
    var $iframes = $(parent.document).find('.targetIframe');

    $iframes.each(function(i, elem) {
        $(elem).height($(document.body).innerHeight());
    });
}
jAndy
  • 231,737
  • 57
  • 305
  • 359
1

It would look like this using .height():

function setHeight() {
  $('.targetIframe', parent.document).height(document.body.offsetHeight);
}

Or for the literal height attribute setting:

function setHeight() {
  $('.targetIframe', parent.document).attr('height', document.body.offsetHeight);
}
Nick Craver
  • 623,446
  • 136
  • 1,297
  • 1,155
  • How to select only the currently onloaded iframe itself?I tried `$(this, parent.document)`,but that's not working . – ollydbg Nov 26 '10 at 14:56
  • @ollydbg - I'm pretty sure you can't, unless the ` – Nick Craver Nov 26 '10 at 15:01
0

Just replace first line with this:

var iframe = $('.targetIframe');
vtambourine
  • 2,109
  • 3
  • 18
  • 27