Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Practical uses
Cross-browser event handler assignment, mouse movement tracking
Version requirement
JavaScript 1.2
Functions
If you haven't experimented with cross-browser event handling scripts, this might be just the primer for you. This example utilizes three event handlers: onclick, onmousemove, and onkeypress. When you first click anywhere in the document space, the JavaScript captures the initial x and y coordinates of the mouse-pointer arrow with respect to the browser window. After that, the status bar displays the x and y coordinates as the user moves the pointer arrow around. Clicking once again "turns off" the coordinate tracking and calculates the pixel distance between the point the user first clicked and current location. You can see this in Figure 6.7 and Figure 6.8.