Microsoft KB Archive/272760

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

Article ID: 272760

Article Last Modified on 5/12/2003

-

APPLIES TO


 * Microsoft Internet Explorer 5.01
 * Microsoft Internet Explorer (Programming) 5.01 SP1
 * Microsoft Internet Explorer 5.5
 * Microsoft Internet Explorer (Programming) 6.0

-



This article was previously published under Q272760



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.



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 &quot;More Information&quot; section for an example.



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



Steps to Reproduce Behavior
 In Microsoft Visual Basic, create a Standard EXE project. Add references to the Microsoft HTML Object Library and the Microsoft Internet Controls.  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 &quot;http://myserver/test.htm&quot; End Sub   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 = &quot; hi &quot; & _ &quot;&quot; & _ &quot;  &quot; doc.open doc.write strHTML doc.Close End Sub </li> Build the application.</li>  Create a new file named Test.htm and paste the following code: hi </li>  Create a new file named TestIFrame.htm and paste the following code: This is my iframe. </li>  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> </li></ol>

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 = &quot;<span style=&quot; & Chr(34) & &quot;display:none&quot; & Chr$(34) & _ &quot;>h &quot; & _ &quot;<script defer=true language=&quot; & Chr(34) & _ &quot;javascript&quot; & Chr(34) & &quot;>&quot; & _ &quot;function insertIFrame&quot; & &quot;{&quot; & _ &quot;   var alltext = &quot; & Chr(34) & _ &quot; Written from VB&quot; & _ &quot;Automation &quot; & _ &quot;<iframe src=\&quot; & Chr(34) & &quot;testiframe.htm\&quot; & Chr(34) & _ &quot; width=200 height=70>&quot; & _ &quot;  &quot; & Chr(34) & &quot;;&quot; & _ &quot;   document.open;&quot; & _ &quot;   document.write(alltext);&quot; & _ &quot;   document.close;&quot; & &quot;}&quot; & _ &quot; &quot;

doc.documentElement.insertAdjacentHTML &quot;beforeEnd&quot;, strScript doc.parentWindow.execScript &quot;insertIFrame&quot;, &quot;jscript&quot;

End Sub

<div class="references_section">