retrieve the location of a page in a frame

F

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
 
M

Michael Winter

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

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
 
F

Fre

Now the code is error free, but i don't get an alertbox?

Thx for reaction Mike!

Frederik
 
M

Michael Winter

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>
 
F

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.aspx?tabindex=1&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
 

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,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top