PRB: ActiveX Control Creation Timing Problems in Internet Explorer 5 (257952)



The information in this article applies to:

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

This article was previously published under Q257952

SYMPTOMS

An HTML page in Internet Explorer 5 may experience some or all of the following related problems when script attempts to access an ActiveX control on that Web page:
  • An access violation or other browser failure.
  • A script error, "Object Required", on any reference to the control.
  • An unexpected control error.
  • The control appears not to have initialized properly; values are not set as expected or defaults show incorrectly.
These problems are timing-dependent and may seem random. They may seem to occur with some uses of the control and not others and be related to the speed with which the Web page loads. These symptoms don't occur in previous versions of Internet Explorer.

CAUSE

Controls may not be completely inplace activated before the window.onload event fires and script begins to access them. (ActiveX controls intended for use in Web pages must be designed to handle this condition.)

RESOLUTION

To resolve these problems, control authors must redesign their controls to handle automation calls that may be invoked before the control is fully inplace active. For additional information on this procedure, click the article number below to view the article in the Microsoft Knowledge Base:

195188 PRB: ActiveX Control Window Is Not Created Until Visible in Internet Explorer

For Web page authors who use a standard ActiveX control that is provided by Microsoft or another company that can't be corrected immediately, the only resolution is to avoid scripting the control until it is fully created, which is not guaranteed until after the control has returned from the window.onload event.

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce Behavior

Because this problem is timing-dependent, it is not possible to provide a guaranteed reproduction scenario. Most Web pages that experience a problem are of the following form:
<HTML>
<HEAD><TITLE>Repro for IE5 ActiveX control problem</TITLE></HEAD>
<BODY>
<OBJECT CLASSID="clsid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" ID="MyControl1">
</OBJECT>
<SCRIPT FOR="window" EVENT="onload" LANGUAGE="JavaScript">
MyControl1.DoSomething();
</SCRIPT>
</BODY>
</HTML>
				
The script call to "MyControl1.DoSomething()" results in the symptoms described previously.

Example Resolution

First, move all script code that uses any ActiveX control on the page out of the window.onload handler or inline script. If there is initialization script code for a control that must be run at load time, move it to a specific function or subroutine. Create a script timer to call this function in window.onload and set it for approximately half a second.

Here is an example workaround for this page:
<HTML>
<HEAD><TITLE>Fix for IE5 ActiveX control problem</TITLE></HEAD>
<BODY>
<OBJECT CLASSID="clsid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" ID="MyControl1">
</OBJECT>
<SCRIPT LANGUAGE="JavaScript">
function InitializeControl()
{
   MyControl1.DoSomething();
}
</SCRIPT>
<SCRIPT FOR="window" EVENT="onload" LANGUAGE="JavaScript">
window.setTimeout("InitializeControl()", 500);
</SCRIPT>
</BODY>
</HTML>
				

Modification Type:MajorLast Reviewed:5/12/2003
Keywords:kbprb KB257952