Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q848 How can I create a function which is performed when a key is pressed, anywhere in the page?

irt.org | Knowledge Base | JavaScript | Event | Q848 [ previous next ]

Q848 How can I create a function which is performed when a key is pressed, anywhere in the page?

In Netscape key presses are only captured when the cursor is within a text field:

<HEAD>
<SCRIPT LANGUAGE="JavaScript1.2"><!--
function netscapeKeyPress(e) {
     alert(e.which + ' pressed');
}

function microsoftKeyPress() {
    alert(window.event.keyCode + ' pressed');
}

if (navigator.appName == 'Netscape') {
    window.captureEvents(Event.KEYPRESS);
    window.onKeyPress = netscapeKeyPress;
}
//--></SCRIPT>

</HEAD>

<BODY onKeyPress="microsoftKeyPress()">
<FORM>
<TEXTAREA>
</TEXTAREA>
</BODY>

Feedback on 'Q848 How can I create a function which is performed when a key is pressed, anywhere in the page?'


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.