You are here: Reference > JavaScript > client-side > event handling > methods > captureEvents (document, window)

captureEvents method (document, window)

Browser support:
Tells the document or window object to capture the specified types of events.
The captureEvents and releaseEvents methods are deprecated and the support for them has been removed in Firefox 3. Although the captureEvents and releaseEvents methods are supported but not implemented in Opera, Google Chrome and Safari.
To remove the capture, use the releaseEvents method. For event capturing, use the addEventListener and setCapture methods instead.


object.captureEvents (eventTypes);
You can find the related objects in the Supported by objects section below.


Required. Integer that specifies the event types to capture.
Predefined constants are available for the possible values of this parameter, in the scope of the Event interface. See the page for the <a href='/lagstsiq.php/#Event'>Event</a> interface for details. The value can be any combination of the following integer constants with the bitwise OR operator (the value of a predefined constant appears in parentheses after the constant in hexadecimal form):
ABORT (0x00400000)
BLUR (0x00002000)
CHANGE (0x00008000)
CLICK (0x00000040)
DBLCLICK (0x00000080)
DRAGDROP (0x00000800)
ERROR (0x00800000)
FOCUS (0x00001000)
KEYDOWN (0x00000100)
KEYPRESS (0x00000400)
KEYUP (0x00000200)
LOAD (0x00080000)
MOUSEDOWN (0x00000001)
MOUSEMOVE (0x00000010)
MOUSEOUT (0x00000008)
MOUSEOVER (0x00000004)
MOUSEUP (0x00000002)
MOVE (0x02000000)
RESET (0x00010000)
RESIZE (0x04000000)
SELECT (0x00004000)
SUBMIT (0x00020000)
UNLOAD (0x00100000)

Return value:

This method has no return value.

Example HTML code 1:

This example illustrates the use of the captureEvents method.
    <script type="text/javascript">
        window.onclick = OnWindowClick;

        function OnWindowClick () {
            alert ('You clicked in the document!');

        function SetCapture () {
            if (window.captureEvents) {     // Firefox, Opera, Google Chrome and Safari
                window.captureEvents (Event.CLICK);

        function RemoveCapture () {
            if (window.releaseEvents) {     // Firefox, Opera, Google Chrome and Safari
                window.releaseEvents (Event.CLICK);
    When the click event is captured by the window, then clicking on a button causes
    the click event to be dispatched to the window first, then to the button.<br />
    The captureEvents and releaseEvents methods do not work in Firefox from version 3!<br /><br />
    <button onclick="alert ('You clicked the button!')">Sample button</button>
    <br /><br />
    <button onclick="SetCapture ()">Set capture!</button>
    <button onclick="RemoveCapture ()">Remove capture!</button>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content