467,161 Members | 1,128 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,161 developers. It's quick & easy.

Making an iframe just big enough, but no bigger

Hi,

Does anyone know a cross-browser way of making an iframe just as big
as the HTML content of its source, but no bigger, either width or
height wise. Using 100% attributes for iframe width and height seem
to make the iframe as big as its parent container. I would also
prefer a solution where there is no scrolling.

Thanks for any help, - Dave

Mar 14 '07 #1
  • viewed: 10695
Share:
3 Replies
Scripsit la***********@zipmail.com:
Does anyone know a cross-browser way of making an iframe just as big
as the HTML content of its source, but no bigger, either width or
height wise.
There is none. That would be against the principles of iframe rendering: the
iframed document is presented autonomously, and the document that embeds it
just offers a display area for it. Using client-side scripting, you might be
able to detect the size requirements of the iframed document, though I doubt
that, and it would surely not be cross-browser.
Using 100% attributes for iframe width and height seem
to make the iframe as big as its parent container.
More or less so.
I would also
prefer a solution where there is no scrolling.
This sounds like you would like to smoothly include a file in another.
That's not really a job for iframe, and it's discussed in the FAQ.

--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/

Mar 14 '07 #2
On Wed, 14 Mar 2007 13:30:19 -0700, la***********@zipmail.com wrote:
Hi,

Does anyone know a cross-browser way of making an iframe just as big
as the HTML content of its source, but no bigger, either width or
height wise. Using 100% attributes for iframe width and height seem
to make the iframe as big as its parent container. I would also
prefer a solution where there is no scrolling.

Thanks for any help, - Dave
There are some scripts on http://www.DynamicDrive.com that will do this as
long as both pages are in the same domain/host.

Search their site for IFRAME
Mar 14 '07 #3

George L. Sexton wrote:
On Wed, 14 Mar 2007 13:30:19 -0700, la***********@zipmail.com wrote:
Hi,

Does anyone know a cross-browser way of making an iframe just as big
as the HTML content of its source, but no bigger, either width or
height wise. Using 100% attributes for iframe width and height seem
to make the iframe as big as its parent container. I would also
prefer a solution where there is no scrolling.

Thanks for any help, - Dave

There are some scripts on http://www.DynamicDrive.com that will do this as
long as both pages are in the same domain/host.

If both pages are from same domain then all you need to do is check
scrollHeight/scrollWidth -

IFrame.width=IFrame.document.body.scrollWidth
IFrame.height=IFrame.document.body.scrollHeight

E.G.-UNTESTED-

<html>
<head><title>Sometr</title>
<script type="text/javascript">

function OpenFrame(){
var Iframe=document.frames[0]
Iframe.src="somePage.html"
Iframe.onload=
function(){
Iframe.width=Iframe.document.body.scrollWidth
Iframe.height=Iframe.document.body.scrollHeight
}
}

</script>
<body style="text-align:center">
<button onclick="OpenFrame()">Text</button><br>
<IFRAME src="about:blank" width="50%" height="30%">your browser
doesn;t support frames(bad browser :-< )</iframe>
</body>
</html>

Mar 15 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Christopher J. Hahn | last post: by
reply views Thread by laredotornado@zipmail.com | last post: by
1 post views Thread by Rich | last post: by
1 post views Thread by gary.comstock@gmail.com | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.