How do I get <TITLE> from frame?

D

D. Alvarado

Hello,
I am trying to find the <TITLE> element of my document. Normally

alert(document.title);

works just fine, but when this statement is within a page that is a
frame in a larger document, the above call always returns the title of
the parent (container) page. Is it possible through JS to deduce the
<TITLE> element of the current page, even if that page is a frame?

Much thanks - Dave
 
M

Mick White

D. Alvarado said:
Hello,
I am trying to find the <TITLE> element of my document. Normally

alert(document.title);

works just fine, but when this statement is within a page that is a
frame in a larger document, the above call always returns the title of
the parent (container) page. Is it possible through JS to deduce the
<TITLE> element of the current page, even if that page is a frame?

Much thanks - Dave

alert(top.document.title);

Mick
 
D

D. Alvarado

Thanks for the reply, but I think I misphrased my question. If my
"top" document is:

<html>
<head><title>Top</title></head>
<body>
<table>
<tr><td><iframe width="200" height="300" src="frame.htm"
name="n"></iframe></td></tr>
</table>
</body>
</html>

and my frame, "frame.htm" is:

<html>
<head><title>Frame</title></head>
<body>
<script type="text/javascript">
alert(document.title);
</script>
</body>
</html>

I want the alert to say "Frame" not "Top," which is what displays with
the current text or even if I include the suggestion
"alert(top.document.title)". Again, much thanks if someone can crack
this enigmatic problem. -
 
I

Ivo

D. Alvarado said:
Thanks for the reply, but I think I misphrased my question. If my
"top" document is:

<html>
<head><title>Top</title></head>
<body>
<table>
<tr><td><iframe width="200" height="300" src="frame.htm"
name="n"></iframe></td></tr>
</table>
</body>
</html>

and my frame, "frame.htm" is:

<html>
<head><title>Frame</title></head>
<body>
<script type="text/javascript">
alert(document.title);
</script>
</body>
</html>

I want the alert to say "Frame" not "Top," which is what displays with
the current text or even if I include the suggestion
"alert(top.document.title)". Again, much thanks if someone can crack
this enigmatic problem. -

Weird, which browser are you using? I get the correct titles when trying
this in IE6/WinME: different results for alert(document.title) and
alert(top.document.title). Both can even be changed dynamically (although
there is litle point in doing that with the framed document). Strange is,
however, that the actual text displayed in the titlebar is not always
updated, when trying forexample, to make top.document.title=document.title,
and then there is no way to confirm if it worked as the top.document.title
string will reflect the new value.
Ivo
 

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,774
Messages
2,569,596
Members
45,144
Latest member
KetoBaseReviews
Top