469,923 Members | 1,584 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,923 developers. It's quick & easy.

retrieve the location of a page in a frame

Fre
Hi, i made script with an alert window that should show me the location of
the page in frame CONTENT (..../artikels.aspx).
But it don't work, i got an error: 'top.frames.1.frames' is empty or nog an
object.

When i try with: alert(top.location)
i get the location of my index page, that works, but when i use the frame
arrays nothing works

Here is my code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
"http://www.w3.org/TR/html4/frameset.dtd">
<html>
<head>
<TITLE>My Title</TITLE>
<script>
alert(top.frames[1].frames[1].frames[0].location);
</script>
</head>
<frameset cols="*,765,*" frameborder="no" border="0" framespacing="0">
<frame name="left" noresize src="bgframe.htm">
<frameset rows="111,*" cols="*" frameborder="NO" border="0"
framespacing="0">
<frame name="head" src="header.htm" noresize scrolling="no">
<frameset cols="*,200" frameborder="NO" border="0" framespacing="0">
<frame name="content" src="artikels.aspx" scrolling="yes">
<frame name="menu" src="menu.aspx" noresize scrolling="no">
</frameset>
</frameset>
<frame name="right" noresize src="bgframe.htm">
</frameset>
<noframes>
<body>
<p>This page uses frames, but your browser doesn't support them.</p>
</body>
</noframes>
</html>


Thx in advance!
Frederik
Jul 23 '05 #1
4 1683
On Sat, 17 Apr 2004 18:51:40 GMT, Fre
<fr*****************************@howest.be> wrote:
Hi, i made script with an alert window that should show me the location
of the page in frame CONTENT (..../artikels.aspx). But it don't work, i
got an error: 'top.frames.1.frames' is empty or nog an object.

When i try with: alert(top.location)
i get the location of my index page, that works, but when i use the
frame arrays nothing works

Here is my code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
"http://www.w3.org/TR/html4/frameset.dtd">
<html>
<head>
<TITLE>My Title</TITLE>
<script>
The type attribute is required. This should read

<script type="text/javascript">
alert(top.frames[1].frames[1].frames[0].location);
</script>


At this point, the browser hasn't begun reading the frame and frameset
elements below, so the frames collection is empty. Either place the script
element below the closing frameset tag, or execute the script "onload".

[snipped frameset HTML]

You should really aim to avoid frames. CSS navigation menus are preferable.

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #2
Fre
Now the code is error free, but i don't get an alertbox?

Thx for reaction Mike!

Frederik
Jul 23 '05 #3
On Sat, 17 Apr 2004 20:43:29 GMT, Fre
<fr*****************************@howest.be> wrote:
Now the code is error free, but i don't get an alertbox?


This is probably what you're after. The frames collection contains all of
the frames in a window, not per frameset. That means that "left" is frame
0, "head" is frame 1, "content" is frame 2, "menu" is frame 3, and "right"
is frame 4.

I took the liberty to make your sample validate (see
<URL:http://validator.w3.org/>).

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
"http://www.w3.org/TR/html4/frameset.dtd">

<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">

<title>My Title</title>

<script type="text/javascript">
function displayFrameSrc( idx ) {
alert( frames[ idx ].location.href );
}
</script>
</head>

<frameset cols="*,765,*" onload="displayFrameSrc(2)">
<frame name="left" noresize src="bgframe.htm" frameborder="0">
<frameset rows="111,*" cols="*">
<frame name="head" src="header.htm" noresize scrolling="no"
frameborder="0">
<frameset cols="*,200">
<frame name="content" src="artikels.aspx" scrolling="yes"
frameborder="0">
<frame name="menu" src="menu.aspx" noresize scrolling="no"
frameborder="0">
</frameset>
</frameset>
<frame name="right" noresize src="bgframe.htm" frameborder="0">
<noframes>
<body>
<p>
This page uses frames, but your browser doesn't support them.
</p>
</body>
</noframes>
</frameset>
</html>

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #4
Fre
Thank you very much Mike to take time solving my problem!
Since you told me that the frames collection contains all of the frames in a
window i understand it perfect now.
I've read many forums before this post and there i've read some articles
with the use of this scriptline:
top.frames[1].frames[0].location (forum i visited for this script:
http://www.asp.net/Forums/ShowPost.a...&PostID=507978)

In the past i worked already with css for some of my school projects but for
this one i started working with frames (don't ask why :) but this is the
last time i do it this way)

Greetz Frederik

"Michael Winter" <M.******@blueyonder.co.invalid> schreef in bericht
news:op**************@news-text.blueyonder.co.uk...
On Sat, 17 Apr 2004 20:43:29 GMT, Fre
<fr*****************************@howest.be> wrote:
Now the code is error free, but i don't get an alertbox?
This is probably what you're after. The frames collection contains all of
the frames in a window, not per frameset. That means that "left" is frame
0, "head" is frame 1, "content" is frame 2, "menu" is frame 3, and "right"
is frame 4.

.... Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)

Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Scott | last post: by
1 post views Thread by Funk | last post: by
1 post views Thread by Georgios Zakitraxis | last post: by
10 posts views Thread by Roland | last post: by
1 post views Thread by Andrew Poulos | last post: by
4 posts views Thread by andreas.w.h.k. :-\) | last post: by
1 post views Thread by michal.podlewski | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.