开发者

How to rewrite this javascript function with jQuery?

开发者 https://www.devze.com 2023-01-26 21:28 出处:网络
function setHeight() { var iframes = parent.document.getElementsByClassName(\'targetIframe\'); for(var i = 0; i < iframes.length; i++)
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?开发者_运维百科


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);
}


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

    $iframes.each(function(i, elem) {
        $(elem).height($(document.body).innerHeight());
    });
}


Just replace first line with this:

var iframe = $('.targetIframe');
0

精彩评论

暂无评论...
验证码 换一张
取 消