Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

BUG: document.write from Automation Client May Change URL to about:blank


View products that this article applies to.

This article was previously published under Q272760

↑ Back to the top


Symptoms

When Internet Explorer is automated from an application that replaces the HTML document using the document.write method, and the HTML code contains an IFrame element, the IFrame may not display the intended page. Also, the URL in the address bar may change to about:blank.

↑ Back to the top


Resolution

The problem does not occur when the script within the page rewrites the document. You can insert the script function that rewrites the page into the document, and then call the script function. See the "More Information" section for an example.

↑ Back to the top


Status

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

↑ Back to the top


More information

Steps to Reproduce Behavior

1.In Microsoft Visual Basic, create a Standard EXE project.
2.Add references to the Microsoft HTML Object Library and the Microsoft Internet Controls.
3.In the Load event of Form1, paste the following code to start Internet Explorer and navigate to a test page:
Dim WithEvents ie As InternetExplorer
Dim doc As IHTMLDocument

Private Sub Form_Load()
    Set ie = New InternetExplorer
    ie.Visible = True
    ie.navigate "http://myserver/test.htm"
End Sub
					
4.To replace the HTML code on the current page, add a button to the form, and then add the following code to the Click event:
Private Sub Command1_Click()
    Dim strHTML As String
    
        Set doc = ie.document
    
        strHTML = "<html><body><DIV>hi<br>" & _
                  "<iframe src=testiframe.htm" & _
                  " width=200 height=70>" & _ 
                  "</iframe><DIV></body></html>" 
        
        doc.open
        doc.write strHTML
        doc.Close
End Sub
					
5.Build the application.
6.Create a new file named Test.htm and paste the following code:
<html>
<body>
hi
</body>
</html>
					
7.Create a new file named TestIFrame.htm and paste the following code:
<html>
<body>
This is my iframe.
</body>
</html>
					
8.Execute the Visual Basic project and then click the button that you added. The address bar in Internet Explorer changes to about:blank, and the IFrame within it does not show the TestIFrame.htm file. The source of the IFrame is
<HTML>blanktestiframe.htm</HTML>
					
To work around this problem, insert script code into the HTML code and call it from the Automation client. You can use the following code in place of the Command1_Click() procedure:
Private Sub Command1_Click()
    Dim strScript As String

    Set doc = ie.document
    
    strScript = "<span style=" & Chr(34) & "display:none" & Chr$(34) & _
                 ">h</span>" & _
                "<script defer=true language=" & Chr(34) & _
                "javascript" & Chr(34) & ">" & _
                "function insertIFrame()" & "{" & _
                "    var alltext = " & Chr(34) & _
                "<html><body>Written from VB" & _
                "Automation<br>" & _
                "<iframe src=\" & Chr(34) & "testiframe.htm\" & Chr(34) & _
                " width=200 height=70>" & _
                "</iframe></body></html>" & Chr(34) & ";" & _
                "    document.open();" & _
                "    document.write(alltext);" & _
                "    document.close();" & "}" & _
                "</script>"

    doc.documentElement.insertAdjacentHTML "beforeEnd", strScript
    doc.parentWindow.execScript "insertIFrame()", "jscript"


End Sub
				

↑ Back to the top


References

For additional information, click the article number below to view the article in the Microsoft Knowledge Base:
185128 HOWTO: Insert Event Handler Into Web Page from WebBrowser App
For more information, see the following Microsoft Web sites:

↑ Back to the top


Keywords: KB272760, kbdhtml, kbbug, kbautomation

↑ Back to the top

Article Info
Article ID : 272760
Revision : 2
Created on : 5/12/2003
Published on : 5/12/2003
Exists online : False
Views : 505