burntsausage
burntsausage

Reputation: 21

Traverse from element within iframe to parent iframe TAG

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?

Upvotes: 2

Views: 2005

Answers (1)

Guard
Guard

Reputation: 6955

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

Upvotes: 2

Related Questions