Getting the width of a frame

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JJ

    #1

    Getting the width of a frame

    I'm working with a web site that has frames defined as:

    <frameset rows="60,*" frameborder="ye s" border="0" framespacing="0 " cols="*"
    bordercolor="#e eeeee" topmargin="0" leftmargin="0" marginheight="0 "
    marginwidth="0" >
    <frame name="topFrame" scrolling="auto " src="top.asp"
    bordercolor="#c ccc66" frameborder="ye s" topmargin="0" leftmargin="0"
    marginheight="0 " marginwidth="0" framespacing="0 ">
    <frameset cols="180,*" frameborder="YE S" border="0" framespacing="2 "
    rows="*" bordercolor="#e eeeee" resize="yes" topmargin="0" leftmargin="0"
    marginheight="0 " marginwidth="0" >
    <frame name="leftFrame " scrolling="auto " src="left.asp"
    bordercolor="#e eeeee" frameborder="no ">
    <frame name="basefrm" src="common/DisplayInformat ion.asp"
    scrolling="auto " bordercolor="#e eeeee" frameborder="no ">
    </frameset>
    </frameset>

    I need to get the width of "leftFrame" from a script running in one of the
    other frames (usually "basefrm").

    I tried parent.leftFram e.width, but it returns "undefined" (but
    parent.leftFram e.name does return "leftFrame" ). I suspect I need something
    before ".leftFrame ", since the framesets are nested. How would I refer to
    leftFrame to get its width?




  • kaeli

    #2
    Re: Getting the width of a frame

    In article <yIydnfvwSdxxBN LcRVn-gw@comcast.com> , jj@nospam.com enlightened us
    with...[color=blue]
    >
    > I need to get the width of "leftFrame" from a script running in one of the
    > other frames (usually "basefrm").
    >
    > I tried parent.leftFram e.width, but it returns "undefined" (but
    > parent.leftFram e.name does return "leftFrame" ). I suspect I need something
    > before ".leftFrame ", since the framesets are nested. How would I refer to
    > leftFrame to get its width?
    >[/color]

    A frame is a window object. There is no such thing as window.width.
    [color=blue]
    > http://www.devguru.com/Technologies/...ef/window.html <[/color]

    As to how to reference the frame from a frameset, assuming your frameset is
    always the main frameset and isn't contained in someone else's, you can use
    top.frames["framename"] or top.frames[index] to reference one of the frames
    or a nested frame.
    The way you referenced it is fine, too. If you got the name, you got it.
    But there is no width of a window. Netscape uses window.innerWid th. IE uses
    document.body.o ffsetWidth. I can't say for other browsers.

    This worked for me. Tested in IE6 / NN7.

    <script type="text/javascript">
    function checkIt()
    {
    var w = top.frames[1].window;
    if (w.innerWidth) alert(w.innerWi dth);
    else if (w.document.bod y.offsetWidth) alert(w.documen t.body.offsetWi dth);
    else alert("no clue.");
    }
    </script>

    --
    --
    ~kaeli~
    Santa's helpers are subordinate clauses.



    Comment

    • JJ

      #3
      Re: Getting the width of a frame

      Before you replied I found another post that had some information and I
      tried this and it worked:

      top.document.al l.leftFrame.wid th;

      I know the window object does not have a width attribute, but according to
      this:

      http://msdn.microsoft.com/library/de...ects/frame.asp

      the frame object does have a "width" attribute.



      "kaeli" <tiny_one@NOSPA M.comcast.net> wrote in message
      news:MPG.1bb9f1 275aba5fe398a14 5@nntp.lucent.c om...[color=blue]
      > In article <yIydnfvwSdxxBN LcRVn-gw@comcast.com> , jj@nospam.com enlightened[/color]
      us[color=blue]
      > with...[color=green]
      > >
      > > I need to get the width of "leftFrame" from a script running in one of[/color][/color]
      the[color=blue][color=green]
      > > other frames (usually "basefrm").
      > >
      > > I tried parent.leftFram e.width, but it returns "undefined" (but
      > > parent.leftFram e.name does return "leftFrame" ). I suspect I need[/color][/color]
      something[color=blue][color=green]
      > > before ".leftFrame ", since the framesets are nested. How would I refer[/color][/color]
      to[color=blue][color=green]
      > > leftFrame to get its width?
      > >[/color]
      >
      > A frame is a window object. There is no such thing as window.width.
      >[color=green]
      > > http://www.devguru.com/Technologies/...ef/window.html <[/color]
      >
      > As to how to reference the frame from a frameset, assuming your frameset[/color]
      is[color=blue]
      > always the main frameset and isn't contained in someone else's, you can[/color]
      use[color=blue]
      > top.frames["framename"] or top.frames[index] to reference one of the[/color]
      frames[color=blue]
      > or a nested frame.
      > The way you referenced it is fine, too. If you got the name, you got it.
      > But there is no width of a window. Netscape uses window.innerWid th. IE[/color]
      uses[color=blue]
      > document.body.o ffsetWidth. I can't say for other browsers.
      >
      > This worked for me. Tested in IE6 / NN7.
      >
      > <script type="text/javascript">
      > function checkIt()
      > {
      > var w = top.frames[1].window;
      > if (w.innerWidth) alert(w.innerWi dth);
      > else if (w.document.bod y.offsetWidth) alert(w.documen t.body.offsetWi dth);
      > else alert("no clue.");
      > }
      > </script>
      >
      > --
      > --
      > ~kaeli~
      > Santa's helpers are subordinate clauses.
      > http://www.ipwebdesign.net/wildAtHeart
      > http://www.ipwebdesign.net/kaelisSpace
      >[/color]


      Comment

      • kaeli

        #4
        Re: Getting the width of a frame

        In article <y4OdnQKuoo7PQs 3cRVn-hQ@comcast.com> , jj@nospam.com enlightened us
        with...[color=blue]
        > Before you replied I found another post that had some information and I
        > tried this and it worked:
        >
        > top.document.al l.leftFrame.wid th;
        >
        > I know the window object does not have a width attribute, but according to
        > this:
        >
        > http://msdn.microsoft.com/library/de...ects/frame.asp
        >
        > the frame object does have a "width" attribute.
        >[/color]

        I hope you only have to support IE. ;)

        Glad you found a solution.


        --
        --
        ~kaeli~
        With her marriage, she got a new name and a dress.



        Comment

        • JJ

          #5
          Re: Getting the width of a frame

          Unfortunately, in this case, it does only need to support IE. It's not
          really a publicly accessible web site, and parts of it use ActiveX controls.

          (Even though we only support IE, I try to write everything I do so it
          supports other browsers also, to the extent that I can.)


          "kaeli" <tiny_one@NOSPA M.comcast.net> wrote in message
          news:MPG.1bbb4e edbcc95d8698a15 0@nntp.lucent.c om...[color=blue]
          > In article <y4OdnQKuoo7PQs 3cRVn-hQ@comcast.com> , jj@nospam.com enlightened[/color]
          us[color=blue]
          > with...[color=green]
          > > Before you replied I found another post that had some information and I
          > > tried this and it worked:
          > >
          > > top.document.al l.leftFrame.wid th;
          > >
          > > I know the window object does not have a width attribute, but according[/color][/color]
          to[color=blue][color=green]
          > > this:
          > >
          > >[/color][/color]
          http://msdn.microsoft.com/library/de...ects/frame.asp[color=blue][color=green]
          > >
          > > the frame object does have a "width" attribute.
          > >[/color]
          >
          > I hope you only have to support IE. ;)
          >
          > Glad you found a solution.
          >
          >
          > --
          > --
          > ~kaeli~
          > With her marriage, she got a new name and a dress.
          > http://www.ipwebdesign.net/wildAtHeart
          > http://www.ipwebdesign.net/kaelisSpace
          >[/color]


          Comment

          Working...