Jump to content

Recommended Posts

Hi guys

 

I've struggled with a very annoying problem for the last two hours. I simply can't get IE8 to trigger onKeyDown and onKeyPress. Included is a minimal working example. It works great in Firefox, Safari, Chrome and Opera. I vaguely remeber it triggering in IE8 at some point during this evening but if it did I've forgotten what made it work.

 

The body tag has onKeyPress and onKeyDown call the function test() which simply displays an alert.

 

What am I doing wrong?

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" dir="ltr">

<head>
<title>ie8 onkeyup onkeypress test</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />

<script type="text/javascript">
function test(e) {
alert("ie8 come on");
}
</script>


</head>

<body onKeyPress="return test(event)" onKeyDown="return test(event)">

<p>some text</p>

</body>

</html>

 

Best regards and thank you

- Wuhtzu

Problem solved :)

 

I didn't anticipate IE to actually restrict the "onKeyPress" and "onKeyDown" to the actual area of the <body>-tag. So The reason why I didn't see anything was because my mouse wasn't hovering over the body area which was only surrounding the "some text"-text in the upper left corner.

 

So in some way IE actually behaved quite rationally and it turns out that either Safari, Firefox and Opera automatically enlarges the <body> to fill the whole screen or events on the body tag fire even though the mouse isn't actually hovering over the body.

 

On the other hand, why should keyboard related events have anything to do with the position of the cursor? You can't really in my opinion determine if the keyboard is in the <body>-area or not. You could of cause base it on the markers position (not cursor, marker) but that's also a bad idea. So I guess i like firefox, safari and operas handling better.

 

Thanks for reading and thinking guys!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.