By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,900 Members | 1,364 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,900 IT Pros & Developers. It's quick & easy.

Getting the width of a frame

P: n/a
JJ
I'm working with a web site that has frames defined as:

<frameset rows="60,*" frameborder="yes" border="0" framespacing="0" cols="*"
bordercolor="#eeeeee" topmargin="0" leftmargin="0" marginheight="0"
marginwidth="0">
<frame name="topFrame" scrolling="auto" src="top.asp"
bordercolor="#cccc66" frameborder="yes" topmargin="0" leftmargin="0"
marginheight="0" marginwidth="0" framespacing="0">
<frameset cols="180,*" frameborder="YES" border="0" framespacing="2"
rows="*" bordercolor="#eeeeee" resize="yes" topmargin="0" leftmargin="0"
marginheight="0" marginwidth="0">
<frame name="leftFrame" scrolling="auto" src="left.asp"
bordercolor="#eeeeee" frameborder="no">
<frame name="basefrm" src="common/DisplayInformation.asp"
scrolling="auto" bordercolor="#eeeeee" 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.leftFrame.width, but it returns "undefined" (but
parent.leftFrame.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?


Jul 23 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
In article <yI********************@comcast.com>, jj@nospam.com enlightened us
with...

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

I tried parent.leftFrame.width, but it returns "undefined" (but
parent.leftFrame.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?

A frame is a window object. There is no such thing as window.width.
http://www.devguru.com/Technologies/...ef/window.html <


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.innerWidth. IE uses
document.body.offsetWidth. 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.innerWidth);
else if (w.document.body.offsetWidth) alert(w.document.body.offsetWidth);
else alert("no clue.");
}
</script>

--
--
~kaeli~
Santa's helpers are subordinate clauses.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #2

P: n/a
JJ
Before you replied I found another post that had some information and I
tried this and it worked:

top.document.all.leftFrame.width;

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" <ti******@NOSPAM.comcast.net> wrote in message
news:MP************************@nntp.lucent.com...
In article <yI********************@comcast.com>, jj@nospam.com enlightened us with...

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

I tried parent.leftFrame.width, but it returns "undefined" (but
parent.leftFrame.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?

A frame is a window object. There is no such thing as window.width.
http://www.devguru.com/Technologies/...ef/window.html <


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.innerWidth. IE uses document.body.offsetWidth. 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.innerWidth);
else if (w.document.body.offsetWidth) alert(w.document.body.offsetWidth);
else alert("no clue.");
}
</script>

--
--
~kaeli~
Santa's helpers are subordinate clauses.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #3

P: n/a
In article <y4********************@comcast.com>, jj@nospam.com enlightened us
with...
Before you replied I found another post that had some information and I
tried this and it worked:

top.document.all.leftFrame.width;

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.


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

Jul 23 '05 #4

P: n/a
JJ
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" <ti******@NOSPAM.comcast.net> wrote in message
news:MP************************@nntp.lucent.com...
In article <y4********************@comcast.com>, jj@nospam.com enlightened us with...
Before you replied I found another post that had some information and I
tried this and it worked:

top.document.all.leftFrame.width;

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.


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

Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.