By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,739 Members | 1,060 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,739 IT Pros & Developers. It's quick & easy.

Making an iframe just big enough, but no bigger

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a

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.