Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    New Coder
    Join Date
    Jan 2003
    Posts
    49
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Dimensions of a frame's source document

    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.
    ~CGameProgrammer( );

  • #2
    Regular Coder
    Join Date
    Aug 2002
    Location
    São Paulo, Brazil
    Posts
    367
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you need it only IE, you can use table.offsetHeight and table.offsetWidth, ie;

    <table id="tblSuitableName" ...
    ...
    </table>
    <script>

    alert(tblSuitableName.offsetHeight+"\n"+tblSuitableName.offsetWidth);


    </script>
    /Daniel

  • #3
    New Coder
    Join Date
    Jan 2003
    Posts
    49
    Thanks
    0
    Thanked 0 Times in 0 Posts
    No, you don't understand -- the table is in another document. I have an IFrame tag like this:

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

    And I need to set its height to the height of PostContents.html, or of the table that's in PostContents.html.
    ~CGameProgrammer( );

  • #4
    Senior Coder joh6nn's Avatar
    Join Date
    Jun 2002
    Location
    72° W. 48' 57" , 41° N. 32' 04"
    Posts
    1,887
    Thanks
    0
    Thanked 1 Time in 1 Post
    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 ?
    bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

    i am a loser geek, crazy with an evil streak,
    yes i do believe there is a violent thing inside of me.

  • #5
    Regular Coder
    Join Date
    Aug 2002
    Location
    São Paulo, Brazil
    Posts
    367
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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>

    Code:
    // Body height
    iPosts.style.height=self.frames("iPosts").document.body.scrollHeight;
    or

    Code:
    // Table height
    iPosts.style.height=iPosts.table.offsetHeight;
    /Daniel

  • #6
    New Coder
    Join Date
    Jan 2003
    Posts
    49
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

    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?
    Last edited by CGameProgrammer; 01-22-2003 at 10:53 PM.
    ~CGameProgrammer( );

  • #7
    New Coder
    Join Date
    Jan 2003
    Posts
    49
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    Last edited by CGameProgrammer; 01-22-2003 at 11:24 PM.
    ~CGameProgrammer( );

  • #8
    New Coder
    Join Date
    Jan 2003
    Posts
    49
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    Last edited by CGameProgrammer; 01-23-2003 at 03:31 AM.
    ~CGameProgrammer( );

  • #9
    Senior Coder joh6nn's Avatar
    Join Date
    Jun 2002
    Location
    72° W. 48' 57" , 41° N. 32' 04"
    Posts
    1,887
    Thanks
    0
    Thanked 1 Time in 1 Post
    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
    clientHeight

    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
    bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

    i am a loser geek, crazy with an evil streak,
    yes i do believe there is a violent thing inside of me.

  • #10
    New Coder
    Join Date
    Jan 2003
    Posts
    49
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    ~CGameProgrammer( );

  • #11
    New Coder
    Join Date
    Jan 2003
    Posts
    49
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey, according to this site:
    JavaScript Programming [style.display]

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

  • #12
    Senior Coder joh6nn's Avatar
    Join Date
    Jun 2002
    Location
    72° W. 48' 57" , 41° N. 32' 04"
    Posts
    1,887
    Thanks
    0
    Thanked 1 Time in 1 Post
    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>
    Last edited by joh6nn; 01-23-2003 at 06:03 AM.
    bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

    i am a loser geek, crazy with an evil streak,
    yes i do believe there is a violent thing inside of me.

  • #13
    New Coder
    Join Date
    Jan 2003
    Posts
    49
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    ~CGameProgrammer( );

  • #14
    Regular Coder
    Join Date
    Aug 2002
    Location
    São Paulo, Brazil
    Posts
    367
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    iPosts.style.height=self.frames("iPosts").document.body.scrollHeight;
    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.
    /Daniel

  • #15
    New Coder
    Join Date
    Jan 2003
    Posts
    49
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    ~CGameProgrammer( );


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •