- var myDiv = new Element('div' { 'tabindex': '0' })
- myDiv.observe('keypress', function(e) {
- var code;
- if (!e) var e = window.event;
- if (e.keyCode) code = e.keyCode;
- else if (e.which) code = e.which;
- alert(String.fromCharCode(code));
- });
2.11.2009
Attaching keyboard events to alternative browser objects
It took me way too long to find out why I could not listen to keyboard events for DOM objects other than the window, form objects, or links. All you have to do is give the div or any other DOM element a tabindex. Below is an example using the prototype framework.
Labels:
GUI,
Javascript,
Prototype
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment