2

I have multiple iframes on the page and need to access the parent Iframe element from the iframe's html element, in order to get the Iframes's height.

So from this:

var htmlElement = $('iframe').contents().find('html');

The following won't work:

var iframeHeight = htmlElement.parents('iframe').attr('height');

Can anyone help please?

  • try htmlElement.parent().height() – Evan Oct 13 '11 at 17:37
  • "need to access the parent Iframe element from the iframe's html element, in order to get the Iframes's height." That's like saying "i need to step forward and step back in order to stay in the same position" why not just do `$('iframe').attr('height');` or `each()` through the iframes and grab their height? – Cory Danielson Oct 13 '11 at 17:37

1 Answers1

2

Pardon, edit (based on How to access parent Iframe from javascript)

var iframe = null;
parent.$("iframe").each(function(iel, el) {
  if(el.contentWindow === window)
      iframe = el;
});
if (iframe)
    iframe.height()

This needs that the parent window (the one having an iframe) has jQuery

Community
  • 1
  • 1
Guard
  • 6,816
  • 4
  • 38
  • 58