Window title

JavaScript FAQ | JavaScript Windows FAQ  

Question: How do I change a window's title, i.e. the text on the window's title bar?

Answer: You can change the window title in two different ways:

  • Set window.document.title or winRef.document.title to the new title. (This will work for changing the title of the current browser window or the title of another script-generated window, with window reference winRef)
  • Overwrite the entire HTML source code in the window. (This is mostly applicable to changing the title of another window.)

Example: Set the title of the current window via window.document.title:

Notes: To change another window's title by overwriting its HTML source code, your script can write to that window a string beginning with the following HTML code:

'<html><head><title>Your new title here</title></head>'
Note also that rewriting another window's content will erase everything previously displayed in that window. Therefore, if you want the window's content to stay, then, after changing the window title, you'll have to write the old content to that window once again. (If your script does not know what the old content was, you'd rather not change the window title either!)

For more information on writing script-generated content to another window, see Writing to a Window.

See also:
How do I open a new browser window?
How do I close a window?
How do I test whether my other window is still open?

Copyright © 1999-2011,