2

I have an iFrame in Dynamics CRM (2011 on premise) which contains an aspx file which loads transaction line items (like an invoice line item). The quantity of line items is highly variable, from 1 to 8,000. I need to adjust the height of the iFrame so it doesn't show the vertical scroll bars. How can I achieve this? Right now I'm using this JS function but it's highly inaccurate:

function setIframeHeight() {
        var rowcount = getRowCount();
        var multiplier = 19;

        if (rowcount < 25) {
            multiplier = 13;
        }
        else if (rowcount > 50) {
            multiplier = 23;
        }
        else if (rowcount > 150) {
            multiplier = 32;
        }
 window.parent.parent.frames[0].document.getElementById('IFRAME_TransactionProduct_RA_d').parentNode.height = rowcount * multiplier;
    }
Filburt
  • 17,626
  • 12
  • 64
  • 115
pnduke
  • 183
  • 3
  • 15

1 Answers1

3

You can use the jquery offset().top function:

http://api.jquery.com/offset/

to determine the height of your page by getting the top of your lowest control on your page:

function setIframeHeight() {
    var element = $('#idOfLowestControlOnPage');

   window.parent.parent.frames[0].document.getElementById('IFRAME_TransactionProduct_RA_d').parentNode.height = element.offset().top + element.height();
}
Greg Oks
  • 2,700
  • 4
  • 35
  • 41