0

The site I'm working on loads several iframes onto the page. When each iframe is loaded I want a function that is within the loaded iframe to change the height of that iframe. Most solutions for this type of issue seem to involve an id which won't work for me. jQuery(window).height() seems able to get the height of the iframe but cannot be used to set it. What I've tried This is code that I've put in the head of the iframe I want to change the height of.

jQuery(document).ready(function () {
var newHeight = 500;
jQuery(window).height(newHeight);
window.innerHeight = newHeight;
})

Note it's for a module and I can't put code in the parent page.... and it'll be tricky to add an id.

I'v also tried variations of this

jQuery('iframe', window.parent.document).each(function (){ 
var newHeight = aUniqueValue; 
jQuery(this).attr("height",newheight); })

but this changes the height of all iframes to the last newHeight value of the last loaded iframe.

I seem to have worked out the solution which I couldn't find online:

jQuery(window.frameElement).height(newHeight);
  • 1
    Can you share what you have tried? – Jay Blanchard Aug 05 '14 at 17:32
  • Yes, this question is very broad as there are many ways to achieve this all dependent on the structure of your current document. IDs are only the norm in examples because they are so easy, and it could work for you just saying (you just have to make it work).. – skrilled Aug 05 '14 at 17:34
  • possible duplicate of [jquery get height of iframe content when loaded](http://stackoverflow.com/questions/3846132/jquery-get-height-of-iframe-content-when-loaded) – skrilled Aug 05 '14 at 17:34
  • Thanks for your responses to my first question on SO :). I've added some of my attempts. I find it add that jQuery(window).height() returns the height of the iframe but jQuery(window).height(newHeight) doesn't change it. Does the fact that the iframe has an attribute height in the tag override it? – Russell Ward Aug 05 '14 at 18:42

0 Answers0