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



The information in this article applies to:

  • Microsoft Internet Explorer (Programming) 5
  • Microsoft Internet Explorer (Programming) 5.01
  • Microsoft Internet Explorer (Programming) 5.01 SP1
  • Microsoft Internet Explorer (Programming) 5.5

This article was previously published under Q296113

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: For additional information, click the article number below to view the article in the Microsoft Knowledge Base:

263033 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:

Modification Type:MajorLast Reviewed:5/11/2006
Keywords:kbbug kbDHTML kbnofix KB296113