Recently, the OCX control is being made, but this control is not an open web page that needs to be initialized, but is dynamically created as needed, when the control is initialized, it needs to get its DOM object in the Web page, and the method to invoke the control immediately after creation.
The first method is as follows:
1 var ctrl = Document.createelement (' object '); 2 ctrl.classid = ' clsid:dcc16727-7a51-47b4-b38e-b020eaaf0584 '; 3 document.body.appendChild (ctrl);
This method does not have any problems in IE11, but in IE9, the control is initialized when it gets its DOM object in the Web page.
By testing, adding the appropriate HTML code directly to the page can be obtained at the time the control is initialized to its DOM object in the Web page.
<HTML><HEAD><TITLE>ATL test page for Object Test3</TITLE></HEAD><BODY><OBJECTID= "Test3"CLASSID= "clsid:dcc16727-7a51-47b4-b38e-b020eaaf0584"></OBJECT></BODY></HTML>
Search on the Internet, found such an article, "FAQ: How to dynamically create and access page elements," his idea is in the OCX with the insertAdjacentHTML method created. This method does not solve the problem of "the control does not get its DOM object in the Web page when it is initialized."
Reading the idea of this article, reminds me of the previous view of the Dom Bridge, Reflow and redraw concept (refer to "high-performance JavaScript DOM programming and Reflow and Redraw"), call getElementById will cause the bridge, the bridge will cause reflow and redraw.
Based on this concept, you want to create the control through innerHTML, is not the same as the first to write the HTML code is the same. The final test, this method is feasible.
The final code is as follows:
var div = document.createelement (' div '= ' <object id= "Test4" classid= "clsid:d cc16727-7a51-47b4-b38e-b020eaaf0584 "></OBJECT>"= document.getElementById (' Test4 ');
How to get its DOM object in a Web page when the control is initialized, refer to my other article, "getting its DOM object in a Web page when OCX is initialized."
Dynamically create and access page elements