July 28, 2000 - Manipulating the Document's Title | WebReference

July 28, 2000 - Manipulating the Document's Title

Yehuda Shiran July 28, 2000
Manipulating the Document's Title
Tips: July 2000

Yehuda Shiran, Ph.D.
Doc JavaScript

Both Internet Explorer and Netscape Navigator display the document's title in the title bar, together with the browser name (Microsoft Internet Explorer or Netscape). You can set the document's title by the <TITLE></TITLE> pair in the HEAD portion. The browsers behave differently if you don't specify the title as above or the string between <TITLE> and </TITLE> is empty or includes only blank characters. Internet Explorer uses the the document's full URL as its title, and displays it on the title bar. Netscape Navigator does not display any title in this case, except the browser name, Netscape.

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 in between <TITLE> and </TITLE>, but they don't affect the title bar.

You can manipulate the document's title via the document.title property. You can both set and use it in many different ways. A simple assignment may look like this:

document.title = "This is tip number 28 in July 2000";

You can now the write the document's title to the body of the document:

document.write("<CENTER><H1>" + document.title + "</H1></CENTER>");

The following line is the result of the above two JavaScript statements: