Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting Title 2

Status
Not open for further replies.

jammer1221

Programmer
Jul 30, 2003
352
0
0
US
Hey everyone, I was wondering how you get the title tag of a page inside of an Iframe. I know you can edit the main page's title tag with the document.title but how would you find the title inside the iframe which is inside the main document.
 
First: How can an iframe have a visible title? Why would you want to access it, since it is never displayed?

Anyway, how about document.frames['myiframe'].document.title?

--Chessbot

"In that blessed region of Four Dimensions, shall we linger on the threshold of the Fifth, and not enter therein? Ah, no! [...] Then, yielding to our intellectual onset, the gates of the Sixth Dimension shall fly open; after that a Seventh, and then an Eighth -- --" Flatland, A. Square (E. A. Abbott)
 
You can use the frames collection:

if your iframe's name was "theFrame", you could use this:

alert(frames['theFrame'].document.title);

Here's a test I did. Call this first one "test.html":
Code:
<html>
<head>
<title>This is the main page title</title>
</head>
<body>
<p>Iframe below:</p>
<p><button onClick="alert(document.title);">Click for the main title</button></p>
<p><button onClick="alert(frames['theFrame'].document.title);">Click for the iFrame title</button></p>
<iframe src="iframe.html" name="theFrame" id="theFrame" height="30" width="30"></iframe>
</body>
</html>

And here's the code for iframe.html
Code:
<html>
<head>
<title>The IFrame Title</title>
</head>
<body bgcolor="#FFFF00">
i Frame
</body>
</html>


Have fun

Jon

________________________________________
Give a man a match, he'll be warm for a minute. But light him on fire, and he'll be warm for the rest of his life.
 
Wow you guys are fast, cheesbot I must not of explained well enough but both of you guys answered the question...Thanks alot
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top