Marcus Frödin
Marcus Frödin

Reputation: 12892

Getting the height of a frame in javascript

I'm currently working in a system with a bit of a legacy presentation layer -- it uses frames (actual, in a frameset frames).

To get some event handling up and running I would like to get events when the frame resizes or at least be able to measure the height of the frame somehow. There seems to be no cross browser way to do this. Has anyone tried anything like this?

Upvotes: 2

Views: 13172

Answers (1)

Sachin Shanbhag
Sachin Shanbhag

Reputation: 55499

Try this - Also you might have to try this on all browsers too -

<!-- 
     Example File From "JavaScript and DHTML Cookbook"
     Published by O'Reilly & Associates
     Copyright 2003 Danny Goodman
-->


function getFrameSize(frameID) {
    var result = {height:0, width:0};
    if (document.getElementById) {
        var frame = parent.document.getElementById(frameID);
        if (frame.scrollWidth) {
            result.height = frame.scrollHeight;
            result.width = frame.scrollWidth;
        }
    }
    return result;
}

Upvotes: 4

Related Questions