views:

338

answers:

1

I have a JavaScript application that is being loaded in an iframe (via a Liferay portlet). The actual HTML is just an empty tag and the JS is loaded when the document is loaded.

When Liferay loads the page in the iframe, it resizes the frame based on the body.scrollHeight property which ends up being 0 since there is no real content in the page before it is loaded.

Is there a way to to style or modify the page in such a way that body.scrollHeight will give a reasonable value and not zero?

I've tried setting the body height to 100% and adding an   but that didn't work.

+1  A: 

You could set a javascript event in <body onload="doStuff()"> which would then have the scrollheight poperly set when it's called.

Or set the CSS to a fixed pixel height like body { height: 250px }

Squeegy
What would doStuff() do to change the scrollHeight property?
Kevin
I think the issue is that the iframe is reading the scrollHeight property of the page when the *iframe* is loaded (iframe.onload), not when the page itself is loaded (body.onload).
Kevin
If I set the height to be fixed, I'm stuck with that height in the iframe
Kevin
So you want the iframe to be able to tell you what the `scrollHeight` will be once it loads it's content? How would it possibly do that? You either have to set it to something before it loads, or let it report it's `scrollheight` after it loads. But if it hasn't loaded any content, it can't know how much content it might load.
Squeegy
Fair enough. Is it possible to change the iframe height from within the embedded page?
Kevin
I don't think the iframe has access to it's enclosing page in that way due to potential security issues (but I could be wrong). It may work if the page and iframe are loaded form the same domain. Otherwise, I'm sure that won't work due to cross domain security issues.
Squeegy
They are in the same domain. Ideally, I'd like the child to be able to set the height of the parent iframe when the child page is loaded
Kevin
If you have access to the page making the embedding the iframe, can you just delays it's iframe setup with a `setTimeout()`?
Squeegy
I don't have access to the page that actually creates the iframe, just the content that the iframe is including.
Kevin