change iframe height from within iframe

I am wondering if it is possible to change the height of an iframe from within that iframe?

Here is the scenario: I open up a lightbox with an iframe (h:500, w:400). Within the iframe there is a 3 page wizard. The first page needs 500px height, but the second page of the wizard is really short, so it'd be nice if I can change the height to 200px with a call, for example: parent.Control.Modal.changeHeight("200px");

Is it possible to do, or has anybody done this? It'd be even cooler if the height changes with some cool Effect as well, but am OK with an 'old-school' height change, too :)

Thanks. Xavier

Posted November 27th, 2007 at 1:27pm by xavier

Hi Xavier,

You should be able to do this using Scriptaculous, making a call to Effect.Scale on the modalcontainer element. Be sure to disable content scaling to avoid inner elements being resized as well.

Ben

Posted November 28th, 2007 at 5:22am by bbodien

Hi Xavier,

You should be able to do this using Scriptaculous, making a call to Effect.Scale on the modalcontainer element. Be sure to disable content scaling to avoid inner elements being resized as well.

Ben

Posted November 28th, 2007 at 5:23am by bbodien

Here's a function I got from a book. You run it from outside the iframe. Maybe put it in the afterOpen handler.


function adjustIFrameSize(id)   {   // from "JavaScript & DHTML Cookbook" (O'Reilly)
    var myIFrame = document.getElementById(id);
    if (myIFrame)   {
        if (myIFrame.contentDocument && myIFrame.contentDocument.body.offsetHeight) {
            // W3C DOM (and Mozilla) syntax
            myIFrame.height = myIFrame.contentDocument.body.offsetHeight;
        } else if (myIFrame.Document && myIFrame.Document.body.scrollHeight)    {
            myIFrame.height = myIFrame.Document.body.scrollHeight;
        }
    }
}

Posted November 30th, 2007 at 10:48am by Hamcake

Login or Register to Post