document.onKeyDown

JavaScript1.0+, JScript1.0+ Nav2+, IE3+ Syntax

document.onKeyDown

Description

The onKeyDown event handler specifies what should happen when any key is pressed when the Document object is in focus.

Example

In Listing 7.148, the script in the <head> of the document specifies a function to handle all KeyDown events in the document. To be able to do this, the document's captureEvents() method is used to capture all events of type Event.KEYDOWN. When any key is pressed within the page, the document's event handler generates an alert box notifying the user of the event.

Listing 7.148 Handle the KeyDown Event with the onKeyDown Event Handler
 <html> <head> <script language="JavaScript1.2"> <!--Hide // Tell the browser you ...

Get Pure JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.