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,387
  • 7
  • 27
  • 29

3 Answers3

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

    $iframes.each(function(i, elem) {
        $(elem).height($(document.body).innerHeight());
    });
}
jAndy
  • 223,102
  • 54
  • 301
  • 354
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
  • 610,884
  • 134
  • 1,288
  • 1,151
  • 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,039
  • 3
  • 18
  • 26