January 21, 2000 - The title Property | WebReference

January 21, 2000 - The title Property

Yehuda Shiran January 21, 2000
The title Property
Tips: January 2000

Yehuda Shiran, Ph.D.
Doc JavaScript

The document's title is set by default to its complete URL. Most Web page authors replace this title with their own text, specified in the <TITLE></TITLE> tag pair in the Head portion. When the Web page includes frames, the title bar displays the title of the document which contains the frameset. Documents providing the content of the frames may include their own titles, but they don't affect the title bar.

The document's title can be scripted via JavaScript as well. Its general reference is document.title. This property cannot be set by just any JavaScript script, but only during construction of the whole document. You can use the title property in may different ways. Suppose you want your document to have a large header containing the document's title. Here is such a page's outline:

<TITLE>Tomer Shiran's Home Page</TITLE>
document.write("<CENTER><H1>" + document.title + "</H1></CENTER>");
// -->

If you do not include the <TITLE></TITLE> tag pair, the title defaults to the complete URL of the document, including any search query, if one is specified. If you place the <TITLE></TITLE> tag pair without text in between, the title still defaults to URL. If the text between the opening and closing tags does not include any characters but one or more space characters, the document is assumed untitled, and document.title remains an empty string, or a space-filled string in the case of the Explorer. The property document.title never evaluates to the URL, unless you specifically write the URL between the <TITLE></TITLE> tags.