Sets the mouse capture to the object that belongs to the current document.
HRESULT setCapture( VARIANT_BOOL containerCapture );
- [in] Specifies one of the following values.
- Default. Events originating in a container are captured by the container.
- Events originating in a container are not captured by the container.
Returns S_OK if successful, or an error value otherwise.
After mouse capture is set to an object, all mouse events for the document are routed to that object. Supported mouse events include onmousedown, onmouseup, onmousemove, onclick, ondblclick, onmouseover, and onmouseout. The IHTMLEventObj::srcElement property of the window event object always returns the object that is positioned under the mouse, instead of the object that has mouse capture.
Mouse clicks automatically trigger the onlosecapture event. To retain mouse capture, call IHTMLElement2::setCapture inside the onclick event handler.
When the containerCapture parameter is set to
true, a container object, such as a div, captures mouse events for all objects in it. By passing the value
false, objects in that container can fire events, and cancel event bubbling.
Drag-and-drop operations, such as the ondragstart event, and text selection through the user interface are disabled when mouse capture is set programmatically. The following key events are unaffected by mouse capture and fire as usual: onkeydown, onkeyup, and onkeypress.
Mouse clicks automatically trigger the onlosecapture event. To retain mouse capture, call IHTMLElement2::setCapture inside the onclick event handler. Mouse capture is also lost if the browser window loses focus for any reason (including alerts or pop-up windows).
Note The containerCapture parameter is available only in Microsoft Internet Explorer 5.5 or later. For earlier versions, do not specify a parameter.