Attaches a behavior to the element.
HRESULT addBehavior( BSTR bstrUrl, VARIANT *pvarFactory, long *pCookie );
- [in] A BSTR that specifies one of the following values.
- Location of the behavior, in URL format. The URL must be bounded by quotation marks, as illustrated in the following sample.
- One of the Windows Internet Explorer default behaviors, identified by its behavior name.
- The ID attribute that is specified in an object tag for the binary implementation of a behavior.
- [in] The address of a VARIANT structure to an IElementBehaviorFactory interface for the behavior.
- [out, retval] A pointer to a long that can be used later to detach the behavior from the element.
Returns S_OK if successful, or an error value otherwise.
This method enables you to attach a behavior without using Cascading Style Sheets (CSS).
Behaviors are subject to cross-frame security rules where a document cannot refer to a behavior on another server or another domain. In this case, the IHTMLElement2::addBehavior method returns E_ACCESSDENIED. For more information, see the Security section in the Introduction to DHTML Behaviors article.
The bstrUrl argument is always treated as the URL of the behavior and not the string name. For example, if bstrUrl is specified as
SIMPLE, no behavior is initialized because MSHTML attempts to find the
SIMPLEIElementBehaviorFactory interface in the local file system. If
#factory#behaviorNameis passed as the bstrUrl argument, then MSHTML parses the string into two parts:
behaviorName. MSHTML then calls
factoryand attempts to instantiate
behaviorName, by passing
behaviorNameas the bstrBehavior argument of the IElementBehaviorFactory::FindBehavior method.
The pvarFactory argument is optional, and has no effect on the interpretation of the bstrUrl argument; therefore, passing a pointer to the pvarFactory argument is not a substitute for specifying the behavior factory in the bstrUrl argument.
This method, and the following remarks, apply only to attached behaviors, which are the original Dynamic HTML (DHTML) behaviors introduced in Microsoft Internet Explorer 5. Element behaviors are a feature in Internet Explorer 5.5 and cannot be added to or removed from an element.