Article ID: 296113 - Last Review: May 11, 2006 - Revision: 3.0

BUG: Script Fails to Change the Document Title of a Web Page

System TipThis article applies to a different operating system than the one you are using. Article content that may not be relevant to you is disabled.
This article was previously published under Q296113

On This Page

Expand all | Collapse all

SYMPTOMS

Internet Explorer fails to change the document title when client-side script sets the innerHTML property of a title object that CreateElement("Title") creates.

RESOLUTION

To work around this problem, use the document.title property to set the title programmatically instead. For sample code that demonstrates this workaround, see the "More Information" section.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Create a new HTML page called Test.htm, and paste the following code:
    <HTML>
    <HEAD>
    <SCRIPT LANGUAGE="JAVASCRIPT">
    
    function runTest()
    {
    	var s ="We should set this as the new title" 
    	var mytitle = document.createElement("TITLE");
    	mytitle.innerHTML = s;
    	alert(s);		
    	document.documentElement.childNodes[0].appendChild(mytitle);
    
    }
    function fix()
    {
    	var s = "Now we change the title";
    	alert(s);
    	document.title = s;	
    }
    </SCRIPT>
    </HEAD>
    <BODY>
    <input type="button" value="Problem" onclick="runTest()"/>
    <input type="button" value="Workaround" onclick="fix()"/>
    </BODY>
    </HTML>
    					
  2. Click Problem. Script is called to set the innerHTML property of a title object. Notice that the title of the Internet Explorer window does not change.
  3. Click Workaround. Script that uses document.title sets the title of the document. Notice that the title of the Internet Explorer window changes.

REFERENCES

For more information about the TITLE element and title object, see the following MSDN Web site:
http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/TITLE.asp (http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/TITLE.asp)
For additional information, click the article number below to view the article in the Microsoft Knowledge Base:
263033  (http://support.microsoft.com/kb/263033/EN-US/ ) BUG: DHTML Dialog Box Does Not Show String Assigned to Document.Title
For more information about developing Web-based solutions for Microsoft Internet Explorer, visit the following Microsoft Web sites:
http://msdn.microsoft.com/ie/ (http://msdn.microsoft.com/ie/)

http://support.microsoft.com/iep (http://support.microsoft.com/iep)

APPLIES TO
  • Microsoft Internet Explorer 5.0
  • Microsoft Internet Explorer 5.01
  • Microsoft Internet Explorer (Programming) 5.01 SP1
  • Microsoft Internet Explorer 5.5
Keywords: 
kbbug kbdhtml kbnofix KB296113
Retired KB ArticleRetired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.