Capture keypress in Javascript (Google Docs)
问题 I'm trying to write a little greasemonkey script/bookmarklet/what have you for Google Docs. The functionality I'd like to add needs a keypress/keyup/keydown event handler (one of those three). Unfortunately, Javascript isn't my forté, and I can't seem to capture (?) a keypress event to while in the edit pane. As a last resort, I've tried the following: javascript:(function(){ els = document.getElementsByTagName("*"); for(i=0;i<els.length;i++){ els[i].onkeypress=function(){alert("hello!");};