Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Possible to resize an Iframe to its content's height?

Reply
Thread Tools

Possible to resize an Iframe to its content's height?

 
 
wolfing1@gmail.com
Guest
Posts: n/a
 
      03-23-2006
Maybe this doesn't make any sense, but is it possible to dynamically
resize an iframe to the height of its contained page? Something that
works in Opera/Firefox/IE.
I can resize it with a
document.getElementById("frameItems").style.height = "200px" for
example, but was wondering if I could access somehow the full size its
inner page would take... which might not make much sense but still who
knows.

 
Reply With Quote
 
 
 
 
wolfing1@gmail.com
Guest
Posts: n/a
 
      03-24-2006

Ian Collins wrote:
> wrote:
> > Maybe this doesn't make any sense, but is it possible to dynamically
> > resize an iframe to the height of its contained page? Something that
> > works in Opera/Firefox/IE.
> > I can resize it with a
> > document.getElementById("frameItems").style.height = "200px" for
> > example, but was wondering if I could access somehow the full size its
> > inner page would take... which might not make much sense but still who
> > knows.
> >

> I haven't tried it, but can you use the size of the iframe's <body> element?
>
> --
> Ian Collins.

Made it work! What I did (copied from somewhere in the web):
In the "inner" page, an onload like this:
<body onload="parent.adjustIFrameSize(window);">

And in the actual page a js function like this:
function adjustIFrameSize(iframeWindow) {
if (iframeWindow.document.height) {
var iframeElement = document.getElementById ("frameItems");
iframeElement.style.height = iframeWindow.document.height + 'px';
iframeElement.style.width = iframeWindow.document.width + 'px';
} else if (document.all) {
var iframeElement = document.all["frameItems"];
if (iframeWindow.document.compatMode &&
iframeWindow.document.compatMode != 'BackCompat') {
iframeElement.style.height =
iframeWindow.document.documentElement.scrollHeight + 5 + 'px';
iframeElement.style.width =
iframeWindow.document.documentElement.scrollWidth + 5 + 'px';
} else {
iframeElement.style.height =
iframeWindow.document.body.scrollHeight + 5 + 'px';
iframeElement.style.width = iframeWindow.document.body.scrollWidth
+ 5 + 'px';
}
}
}

where frameItems is the name of the frame containing the page.
Tested in IE, Firefox and Opera and works in all of them so good enough
for me.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Its a bird, its a plane, its.. um, an Attribute based System? thunk Ruby 14 04-03-2010 10:08 AM
Its a bird, its a plane, its.. um, an Attribute based System? thunk Ruby 0 04-01-2010 10:25 PM
Its a bird, its a plane, no ummm, its a Ruide thunk Ruby 1 03-30-2010 11:10 AM
Need to pass a value from an IFrame to its parent to its parent PKalos@gmail.com Javascript 0 02-02-2006 10:02 AM
Get form values from iframe (1) to iframe (2) inside a layer in iframe (1) Daedalous Javascript 3 01-16-2004 11:08 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57