|
| ||||||||||
| Tags: event handler, flash game, how to, javascript, web site |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| How to Disable Arrow Keys in JavaScript
Code: <script type="text/javascript">
function KeyPressHappened(e){
if (!e) e=window.event;
var key=e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
if(key == 37 || key == 38 || key == 39 || key == 40)
{
e.preventDefault();
return false;
}
return true;
}
document.onkeypress = KeyPressHappened;
</script> |
|
#2
| |||
| |||
| Re: How to Disable Arrow Keys in JavaScript
With help of onkeydown event handler you can solve this issue. The onkeydown event handler will specifies what should occur while press any key which Document object is in focus. So I would like to try below code on your website and then you can disable the arrow up/down key: Code: <script type = "text/javascript">
document.onkeydown = function(ev) {
var key;
ev = ev || event;
key = ev.keyCode;
alert (key)
if(key == 37 || key == 38 || key == 39 || key == 40) {
//e.cancelBubble is supported by IE - this will kill the bubbling process.
ev.cancelBubble = true;
ev.returnValue = false;
}
}
</script> |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "How to Disable Arrow Keys in JavaScript" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Where are the arrow keys on the iPad | Lael | Portable Devices | 5 | 25-02-2011 10:01 PM |
| Character not moving with Arrow keys in Actionscript 3 | Ekavali | Software Development | 5 | 24-11-2010 11:31 PM |
| Problem of arrow keys with VMWARE | D_chapple | Windows Software | 5 | 23-12-2009 10:39 AM |
| Arrow keys not scrolling in Internet Explorer 8 | KAMAL60 | Technology & Internet | 3 | 12-11-2009 10:59 PM |
| Up/down left/right arrow keys not working properly | Nickita in TX | Vista Help | 2 | 06-03-2008 12:48 PM |