Page 1 of 1

Page title.

Posted: Wed Oct 03, 2007 4:04 pm
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.

Posted: Wed Oct 03, 2007 4:16 pm
by Kieran Huggins
document.title is read/write, as far as I know.

Posted: Wed Oct 03, 2007 4:39 pm
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?

Posted: Wed Oct 03, 2007 9:52 pm
by VladSun

Posted: Wed Oct 03, 2007 10:49 pm
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?

Posted: Wed Oct 03, 2007 11:21 pm
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... :)

Posted: Thu Oct 04, 2007 2:26 pm
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

Posted: Thu Oct 04, 2007 3:55 pm
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?

Posted: Thu Oct 04, 2007 4:04 pm
by VladSun
In fact, it depends on you web browser settings :) But I would strongly recommend not to turn this protection off!