How do you capture Keypress event in MSIE on Macintosh

J

Jeff Bowes

Hi,

I am trying to capture the keypress event to change the default
behaviour when the return key is pressed. However, on MSIE on Macintosh
(IE 5.x- at least all the versions I have tried on both OS 9 and OS
10) , when the onkeypress trigger is executed the events charCode and
keyCode are both 0. The event type also shows as "focus" instead of
"keypress". the following is snippets of the code I used.

Javascript:

function keyPress(e) {

if (!e) {
var e = window.event;
}

alert("event keycode is " + e.keyCode);
alert("event type is " + e.type);
alert("charcode is " + e.charCode);

key = (e.keyCode!=undefined) ? e.keyCode : key=e.which;

...

}

HTML:

<BODY onkeypress="return keyPress(event);">


Can anyone tell me how I can get around this bug and capture the key
code. The code performs correctly on IE on the PC.

thanks in advance,

Jeff Bowes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top