Getting the width of a frame

J

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?
 
K

kaeli

[email protected] enlightened us said:
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.

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>

--
 
J

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/default.asp?url=/workshop/author/dhtml/reference/objects/frame.asp

the frame object does have a "width" attribute.



kaeli said:
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.

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
 
K

kaeli

J

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.)


 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top