document.onKeyPress

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

document.onKeyPress

Description

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

Example

In Listing 7.149, the script in the <head> of the document specifies a function to handle all KeyPress events in the document. To be able to do this, the document's captureEvents() method is used to capture all events of type Event.KEYPRESS. 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.149 Handle the KeyPress Event with the onKeyPress Event Handler
 <html> <head> <script language="JavaScript1.2"> <!-- Hide // Tell the browser ...

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.