View Full Version : Dimensions of a frame's source document

01-22-2003, 02:50 AM
I need to have an iframe whose dimensions are exactly equal to the dimensions of the document it links to. If it helps, the linked document simply consists of one table with stuff inside it, so getting the dimensions of the table is good enough.

I need to do this in either JavaScript or ASP, but I haven't been using either for long and I have no idea how to do this.

01-22-2003, 04:55 PM
If you need it only IE, you can use table.offsetHeight and table.offsetWidth, ie;

<table id="tblSuitableName" ...



01-22-2003, 07:39 PM
No, you don't understand -- the table is in another document. I have an IFrame tag like this:

Width = 100%
Height = 0>

And I need to set its height to the height of PostContents.html, or of the table that's in PostContents.html.

01-22-2003, 08:06 PM
i'm not sure i understand. are you trying to make an iframe, that changes it size based on the document in it, or are you trying to make an iframe, where the document in it sizes itself to the size of the iframe ?

01-22-2003, 08:49 PM
Ok, so you want to make the iframe as high as the content of PostContent.html?

<IFrame id="iPosts" Src="PostContents.html" Width = 100% Height = 0></IFrame>

// Body height


// Table height

01-22-2003, 11:31 PM
John: I'm trying to make the iframe size itself to the document. I know it seems like a waste of an iframe, but the reason is I am trying to implement collapseable views... see the webpage I'm working on: Post/View Screenshots (http://www27.brinkster.com/cgame/Screenshots.asp)

I had been using style.display, but that's MSIE-specific. So I'm trying to use iframes and toggle their height between 0 and [fullheight].

Danne: I'll try that, but doesn't document point to the containing document, not PostContents.html?

01-23-2003, 12:00 AM
Wow Danne, it works! Thanks alot! Can you explain it now?

EDIT: Actually, although it worked on the test page, in the actual page it generated an exception error. I have no idea why. All I did was, in Screenshots.asp (I gave the link above) I put the line:

Contents.style.height = self.frames(Contents.name).document.body.scrollHeight;

near the bottom of the ControlView() function, replacing the line that set the height to 240. And that generates an error.

01-23-2003, 12:39 AM
Well I just read that scrollHeight is IE-specific, which is no good to me; I'm trying to write code that works with Netscape, IE, and Opera. It looks like there's no way I can do it; IE is the only browser that supports any method.

Also the post has no 'table' property. It's just the document it links to that has a table in it.

EDIT: Netscape sucks. I got it working by using the clientHeight of the table, which only IE and Opera 7 support.

01-23-2003, 06:44 AM
CGame, dude.

...A book on HTML from 1997 did say that at the time, IE was the only browser that recognized the display style of elements...

'97? that's 6 years old man. everything is supporting style.display now. also, i found this in your code:

Contents.style.height = FrameDoc.body.clientHeight + 32; // IE std-compliant mode

clientHeight is MSIE only; it's not even close to standard. check it out:

display (http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/display.asp)
clientHeight (http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/clientheight.asp)

down at the bottom where it says Standards Information, if it says "there's no standard that applies to this" that means that MS made it up.

i didn't have time to check out why, but in Mozilla ( which is essentially the same as NS6 and 7 ), the collapsing didn't work at all. My guess is that if you want this to come even close to working in more than just IE, you're gonna have to go back to style.display

01-23-2003, 06:54 AM
John: Someone told me, when I had been using style.display, that the thread collapsing didn't work with Opera. I don't know what version they had though.

01-23-2003, 06:58 AM
Hey, according to this site:
JavaScript Programming [style.display] (http://www.dardenhome.com/js/x816712.htm)

...style.display is supported by all major browsers. Damn that person; he made me change what apparently worked fine!

01-23-2003, 06:59 AM
it had to be a pretty old version; i've used style.display succesffully in Opera 6.05.

<edit>It wasn't necessarily working fine. just because it was working in IE, doesn't mean it was working in anything else. IE can be a real piece of crap, and will let you get away with all kinds of stuff, that just shouldn't work. my theory: you unwittingly did something IE specific, or made a typo that IE didn't mind too much. try putting it back the way you had it, and tomorrow ( i'm too tired right now ) we can check it again.</edit>

01-23-2003, 08:47 AM
Possibly, John, but I doubt it -- it's hard to make mistakes when all you're doing is toggling the display between "inline" and "none" :)

I appreciate your help immensely though, and since you're helping me, I would appreciate it if you'd see if my webpage works in Netscape and/or Opera. I've reverted to style.display.

The most questionable part is whether moving the mouse over the titles turns them blue. I use events on a font tag for this, but maybe only IE supports that, I don't know.

01-23-2003, 02:16 PM

iPosts is the id of the element in the current document. self is the same as window, which has a collection of frames. Referring self.frames("iPosts") is the same as using window inside PostContents.html.

01-23-2003, 11:38 PM
Ah, thanks Dan. I would have assumed self.frames( "blah" ) was the same as saying document["blah"].

BTW it occured to me that if I did stick with iframe, a bug would appear - if the screen resolution was too low to fit the frame in its full size then it should be resized, but using clientHeight fixes its height.

01-24-2003, 01:15 AM
CGame, things aren't working in Mozilla or Opera. the first error that popped out at me, was this:

var PostList = document.body.getElementsByTagName( "SPAN" );

for( var N = 0; N < PostList.length; N ++ )
var Post = PostList( N );

see, getElementsByTagName returns an array, but you're calling that array with parenthesis instead of brackets. IE allows that, but technically, it's wrong. IE doesn't do very well as far as getting things right is concerned.

01-24-2003, 02:44 AM
Thanks alot John. The example code I learned from used both parentheses and brackets to reference arrays, which confused me... now I know arrays are the way to go.

EDIT: By the way, it is correct to say childNodes.item(x), right? As opposed to brackets?

01-24-2003, 04:31 AM
i think so. i think that item is a function.

01-24-2003, 05:42 AM
I looked up the item() vs item[] thing in the JavaScript reference page I gave a link to, and it says both are valid. However, IE gives an error when using brackets. Since parentheses work with all browsers, I guess those are the correct way.

Anyway I found out what caused problems with Opera, besides the bracket thing. It lists items incorrectly! Let's say I have this:

<font size=1 id="First">Hello World</font>
<font size=2 id="Second">How are you doing?</font>

The first first font tag should be the span's childNodes.item(0) and the other should be item(1). Well it is with IE, and presumably with Netscape since no one reported errors with it, but with Opera the first font is item(1) and the second is item(3). Items 0 and 2 are regular text (nodeName="#text"). Why? Because it's retarded. Note that the only thing between the tags is a linebreak.

01-24-2003, 07:18 PM
try normalizing the text. i'm not real familiar with the standard DOM, but if you search for normalizing, you should find it.

01-25-2003, 04:37 AM
Normalizing didn't appear to have any effect. From what I've read of it, it just combines multiple #text elements into one. IE does this automatically anyway; a string of text is interpreted as one #text element.