Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

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

You are here: irt.org | FAQ | JavaScript | Event | Q848 [ previous next ]

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?'

©2018 Martin Webb