July 14, 2000 - The setCapture() Method | WebReference

July 14, 2000 - The setCapture() Method

Yehuda Shiran July 14, 2000
The setCapture() Method
Tips: July 2000

Yehuda Shiran, Ph.D.
Doc JavaScript

Usually, an object fires an event when the event occurs within its physical limits on the page. For example, if you specify an onmousemove event for a DIV element, the appropriate event handler kicks in only when the mouse moves inside the DIV box.

Sometimes, though, you want an object to capture events that occur within other objects. You can do it with the setCapture() method:

object.setCapture([flag]);

where flag is an optional parameter equal to either false (no capturing), or true (default).

The following box is designed to capture onmousemove events from the whole document. You can turn this capturing off and on by a mouse click. Play around with the mouse and make sure the setCapture() method is working according to the specifications.

Supported mouse events include onmousedown, onmouseup, onmousemove, onclick, ondblclick, onmouseover, and onmouseout. The srcElement property of the window's event object always returns the object that is positioned under the mouse rather than the object that has mouse capture. The following key events are unaffected by mouse capture, and fire as usual: onkeydown, onkeyup, and onkeypress.

For more on the event model, go to Column 9, The Navigator Event Model, Column 10, The Internet Explorer Event Model, and Column 11, The Cross Browser Event Model.