Page title.

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
figaro11
Forum Commoner
Posts: 64
Joined: Mon Sep 17, 2007 11:49 pm

Page title.

Post by figaro11 »

Hi, I was wondering how do I get the page title in javascript? You know the page title with in the <title> brackets. Is there a JavaScript property for this, that I could modify and what not?

Thanks for reading.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

document.title is read/write, as far as I know.
User avatar
figaro11
Forum Commoner
Posts: 64
Joined: Mon Sep 17, 2007 11:49 pm

Post by figaro11 »

Kieran Huggins wrote:document.title is read/write, as far as I know.
Great! Now all I need to know is how I can place the value of a iframe's document title... :?

EDIT: For example, Google Video has an iframe, but how do they get the document's title the title of the iframe?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

There are 10 types of people in this world, those who understand binary and those who don't
User avatar
figaro11
Forum Commoner
Posts: 64
Joined: Mon Sep 17, 2007 11:49 pm

Post by figaro11 »

VladSun wrote:DOM iframe
Awesome! But how do I get the object of the frame?

I tried:

Code: Select all

alert(document.getElementById("3rdPartyFrame").title);
This doesn't return alert anyting...

EDIT: I believe this is because of the Same Origin Policy. I can't access the properties or methods of an iframe with the src or like, yahoo or something.

How does google do it?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

Probably your iframe source address and the address of the page itself are not in the same domain. So, I don't think you can do this because it is Cross Site Scripting and it is considered to be a security issue.

PS: you are trying to read the wrong title - it is the hint when user puts his mouse over the iframe... :)
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

A frame is a window, you need to access the frame's document object.

Code: Select all

parent.yourFrameName.document.title
check out: http://jennifermadden.com/javascript/frame.html for some example code
User avatar
figaro11
Forum Commoner
Posts: 64
Joined: Mon Sep 17, 2007 11:49 pm

Post by figaro11 »

Kieran Huggins wrote:A frame is a window, you need to access the frame's document object.

Code: Select all

parent.yourFrameName.document.title
check out: http://jennifermadden.com/javascript/frame.html for some example code
The problem is, the loaded web page in the frame is yahoo.com's homepage. If I where to access yahoo's dom, it would be considered cross scripting. I think this is illegal in the web at the moment, right?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

In fact, it depends on you web browser settings :) But I would strongly recommend not to turn this protection off!
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply