NameSilo

Firefox and keydown event inside DIV elements

SpaceshipSpaceship
SpaceshipSpaceship
Namecheap AuctionsNamecheap Auctions
Watch
Impact
0
Hello,
can anybody please explain to me why the following code does not work in Firefox as it does in IE?
In general, how can I capture keydown events inside DIVs with firefox?

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>keydown test</title>
</head>
<script language="JavaScript" type="text/javascript">
function keydown(evt)
{
     obj = document.getElementById("test");
     if(obj)
     {
          if(window.event)
               var key = evt.keyCode;
          else if(evt.which)
               var key = evt.which;
          else
               return true;
          obj.innerHTML += "user pressed '"+String.fromCharCode(key)+"' ("+key+")<br>";
     }
}
</script>
<body>
<div id="test" style="border: 1px solid black; padding: 8px; position: absolute; overflow: visible; left: 0px; top: 0px; -moz-box-sizing: border-box; width:400px; height:100px; font-family:tahoma; font-size:11px; background-color:#CCCC66;" onkeydown="return keydown(event);">
</div>
</body>
</html>

Thanks in advance.
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
CatchedCatched

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back