Notifies the Dynamic HTML (DHTML) behavior that it has been instantiated.
HRESULT retVal = object.Init(pBehaviorSite);
- pBehaviorSite [in]
A pPointer to the IElementBehaviorSite interface through which the Dynamic HTML (DHTML) behavior communicates with MSHTML.
If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
This method is the first notification received by the Dynamic HTML (DHTML) behavior after it is instantiated by MSHTML, through a call to the IElementBehaviorFactory::FindBehavior method. Any initialization that is required for the Dynamic HTML (DHTML) behavior can be done at this point.
You can query the IElementBehaviorSite interface that is passed to the IElementBehavior::Init method for the IElementBehaviorSiteOM interface, the IElementBehaviorSiteCategory interface, the IBindHost interface, and the IServiceProvider interface.
Use the IElementBehaviorSite::GetElement method to get a pointer to the element that the Dynamic HTML (DHTML) behavior is attached to. Note that the pointer returned by a call to the IElementBehaviorSite::GetElement method should not be cached, because caching prevents the behavior from receiving a detach call.
The IElementBehavior::Init method is analogous to running an inline script during the parsing phase of a behavior that uses an HTML Component (HTC) file. Do not use IElementBehavior::Init to implement code that references, creates, or modifies content in the primary document. Instead, use the IElementBehavior::Notify method to detect the oncontentready event and the ondocumentready event, which provide notification on the successful parsing of the element that the behavior is attached to, and the primary document, respectively.
MSHTML calls the IElementBehavior::Notify method to indicate when the element and document to which the DHTML behavior is attached are fully parsed. If the Dynamic HTML (DHTML) behavior must be downloaded, the contents of the document might be parsed before the IElementBehavior::Init method is called, and the IElementBehavior::Notify method is not called.