HTMLWindowEvents4::onclick Event

New for Internet Explorer 9

[This documentation is preliminary and is subject to change.]

Fires when the user clicks the left mouse button on the object.

Syntax


VARIANT_BOOL onclick(
    IHTMLEventObj *pEvtObj
);

Parameters

pEvtObj
[in] Pointer to an IHTMLEventObj interface for the current event. This is the same interface returned from IHTMLWindow2::event.

Return Value

If the event bubbles and is cancellable, return VARIANT_TRUE to prevent the event from bubbling to other event handlers in the document tree. Return VARIANT_FALSE to allow bubbling.

Event DISPID


DISPID_HTMLWINDOWEVENTS4_ONCLICK

The DISPID for this event is defined in mshtmdid.h. Use this value to identify the event handler when implementing IDispatch::Invoke.

Event Information

Bubbles Yes
Cancels Yes
To invoke
  • Click the object.
  • Invoke the IHTMLElement::click method.
  • Press the ENTER key in a form.
  • Press the access key for a control.
  • Select an item in a combo box or list box by clicking the left mouse button or by pressing the arrow keys and then pressing the ENTER key.
Default action Initiates any action associated with the object. For example, if the user clicks an a object, the browser loads the document specified by the IHTMLAnchorElement::href property. To cancel the default behavior, set the returnValue property of the event object to FALSE.

Event Object Properties

The IHTMLEventObj interface contains additional information about the current event. When the onclick event is fired, you can use the IHTMLWindow2::event property to retrieve an IHTMLEventObj interface. To obtain an alternate interface pointer such as IHTMLEventObj2 or IHTMLEventObj3, call QueryInterface on the object.

Available Properties

IHTMLEventObj::button Gets the mouse button pressed by the user.
IHTMLEventObj2::button Gets or sets the mouse button pressed by the user.
IDOMMouseEvent::button New for Internet Explorer 9  Gets the mouse button that caused an event.
IHTMLEventObj::clientX Gets the x-coordinate of the mouse pointer's position relative to the client area of the window, excluding window decorations and scroll bars.
IHTMLEventObj2::clientX Gets or sets the x-coordinate of the mouse pointer's position relative to the client area of the window, excluding window decorations and scroll bars.
IDOMMouseEvent::clientX New for Internet Explorer 9  Gets the x-coordinate of the mouse pointer, relative to the upper-left corner of the viewport (that is, the browser's client area).
IHTMLEventObj::clientY Gets the y-coordinate of the mouse pointer's position relative to the client area of the window, excluding window decorations and scroll bars.
IHTMLEventObj2::clientY Gets or sets the y-coordinate of the mouse pointer's position relative to the client area of the window, excluding window decorations and scroll bars.
IDOMMouseEvent::clientY New for Internet Explorer 9  Gets the y-coordinate of the mouse pointer, relative to the upper-left corner of the viewport (that is, the browser's client area).
IHTMLEventObj::ctrlKey Gets the state of the CTRL key.
IHTMLEventObj2::ctrlKey Gets or sets the state of the CTRL key.
IDOMMouseEvent::ctrlKey New for Internet Explorer 9  Gets a value that indicates whether the Ctrl key is pressed.
IHTMLEventObj::offsetX Gets the x-coordinate of the mouse pointer's position relative to the object firing the event.
IHTMLEventObj2::offsetX Gets or sets the x-coordinate of the mouse pointer's position relative to the object firing the event.
IDOMMouseEvent::offsetX New for Internet Explorer 9  Gets the y-coordinate of the mouse pointer, relative to the target node.
IHTMLEventObj::offsetY Gets the y-coordinate of the mouse pointer's position relative to the object firing the event.
IHTMLEventObj2::offsetY Gets or sets the y-coordinate of the mouse pointer's position relative to the object firing the event.
IDOMMouseEvent::offsetY New for Internet Explorer 9  Gets the y-coordinate of the mouse pointer, relative to the target node.
IHTMLEventObj::screenX Gets the x-coordinate of the mouse pointer's position relative to the user's screen.
IHTMLEventObj2::screenX Gets or sets the x-coordinate of the mouse pointer's position relative to the user's screen.
IDOMMouseEvent::screenX New for Internet Explorer 9  Gets the x-coordinate of the mouse pointer, relative to the upper-left corner of the screen.
IHTMLEventObj::screenY Gets the y-coordinate of the mouse pointer's position relative to the user's screen.
IHTMLEventObj2::screenY Gets or sets the y-coordinate of the mouse pointer's position relative to the user's screen.
IDOMMouseEvent::screenY New for Internet Explorer 9  Gets the y-coordinate of the mouse pointer, relative to the upper-left corner of the screen.
IHTMLEventObj::shiftKey Gets the state of the SHIFT key.
IHTMLEventObj2::shiftKey Gets the state of the SHIFT key.
IDOMMouseEvent::shiftKey New for Internet Explorer 9  Gets a value that indicates whether the Shift key is pressed.
IHTMLEventObj::srcElement Gets the object that fired the event.
IHTMLEventObj2::srcElement Gets or sets the object that fired the event.
IHTMLEventObj::x Gets the x-coordinate (in pixels) of the mouse pointer's offset from the closest relatively positioned parent element of the element that fired the event.
IHTMLEventObj2::x Gets or sets the x-coordinate (in pixels) of the mouse pointer's offset from the closest relatively positioned parent element of the element that fired the event.
IDOMMouseEvent::x New for Internet Explorer 9  Gets the x-coordinate of the mouse pointer, relative to the last positioned ancestor element.
IHTMLEventObj::y Gets the y-coordinate (in pixels) of the mouse pointer's offset from the closest relatively positioned parent element of the element that fired the event.
IHTMLEventObj2::y Gets or sets the y-coordinate (in pixels) of the mouse pointer's offset from the closest relatively positioned parent element of the element that fired the event.
IDOMMouseEvent::y New for Internet Explorer 9  Gets the y-coordinate of the mouse pointer, relative to the last positioned ancestor element.

Refer to the specific event object for additional event properties.

Remarks

If the user clicks the left mouse button, the HTMLWindowEvents4::onclick event for an object occurs only if the mouse pointer is over the object and an HTMLWindowEvents4::onmousedown and an HTMLWindowEvents4::onmouseup event occur in that order. For example, if the user clicks the mouse on the object but moves the mouse pointer away from the object before releasing, no HTMLWindowEvents4::onclick event occurs.

The HTMLWindowEvents4::onclick event changes the value of a control in a group. This change initiates the event for the group, not for the individual control. For example, if the user clicks a radio button or check box in a group, the HTMLWindowEvents4::onclick event occurs after the onbeforeupdate and onafterupdate events for the control group.

If the user clicks an object that can receive the input focus but does not already have the focus, the onfocus event occurs for that object before the HTMLWindowEvents4::onclick event. If the user double-clicks the left mouse button in a control, an HTMLWindowEvents4::ondblclick event occurs immediately after the HTMLWindowEvents4::onclick event.

Although the HTMLWindowEvents4::onclick event is available on a large number of HTML elements, if a Web page is to be accessible to keyboard users, you should restrict its use to the a, input, area, and button elements. These elements automatically allow keyboard access through the TAB key, making Web pages that use the elements accessible to keyboard users. For more information, please see the section on writing accessible Dynamic HTML.

See Also

IHTMLElement::click

Community Additions

Show:
© 2014 Microsoft