Feedback: irt.org FAQ Knowledge Base Q848
Feedback on: irt.org FAQ Knowledge Base Q848
Sent by James D. Albert on July 15, 1999 at 12:01:18: - feedback #305
Worth: Worth reading
Length: Just right
Technical: Just right
Comments: The statement "In Netscape key presses are only captured when the cursor is within a text field" is not entirely true. Using document.captureEvents instead of window.captureEvents (NN4+) should produce the desired results. See http://devedge.netscape.com/docs/manuals/js/client/jsref/handlers.htm#1120393
Sent by Trevor Hastings on January 09, 2001 at 21:26:22: - feedback #2222
Technical: Not technical enough
Comments: Hi folks, I love the irt knowledge base, but the answer for Q848 needs work. Right now it says "In Netscape key presses are only captured when the cursor is within a text field." That might have been true in some earlier version of Netscape, but all version 4, 5, and 6 browsers can capture key presses without any text field. (The catch is that the cursor can't be up in the "Location" box at the top of the screen.) I'm including a script to show what I mean. I hope it helps! - Trevor Hastings ------------------ <HTML> <HEAD> <TITLE>Untitled</TITLE> <SCRIPT LANGUAGE="Javascript"> if (document.layers) { document.captureEvents(Event.KEYPRESS) } document.onKeyPress = getKeyValue; function getKeyValue(e){ if (document.all) { var whichCode = event.which ? event.which : event.charCode ? event.charCode : event.keyCode; } else { var whichCode = e.which ? e.which : e.charCode ? e.charCode : e.keyCode; } alert ("Key value is: " + whichCode) } </SCRIPT> </HEAD> <BODY onKeyPress="getKeyValue(event)"> This is a test. Hit any key to get its value. </BODY> </HTML>
Sent by Miha Novak on June 11, 2002 at 06:47:51: - feedback #3939
Worth: Very worth reading
Length: Just right
Technical: Just right
Comments: If you want to capture events also in for example combo box you can do it in this manner! <HTML> <HEAD> <script language="Javascript"> function NS(e) { if (e.which == 13) { window.alert("You have pressed return");} } function Author() { window.alert("This script was contributed to the WWW by Miha Novak, Slovenia"); } window.captureEvents(Event.KEYPRESS); window.onkeypress = NS; </script> </HEAD> <BODY > <form name="test"> <select name="selection" onkeypress="Javascript:NS(event);"> <option>first option</option> <option>second option</option> <option>third option</option> </select> <input type="button" value="press" name="butt" onClick="Author()"> <input type="text" name="tfield" SIZE="20"> </form> </BODY> </HTML>
|