Filed under: Further Reading
March 4, 2009 • 8:12 pm 0
VNC Makes Me Crazy
March 3, 2009 • 4:35 pm 2
Textbox Focus with Greasemonkey and Javascript
I use IMDB at work a lot, and finally got tired of having to manually click the search box every time I went back to that tab to perform a query. So with a little searching and tweaking, I came up with a Greasemonkey script that not only gives focus to the main search box, but returns focus to it when I hit the ESC key. Here’s the code for those interested:
function focusFirst() {
document.getElementsByTagName('input')[0].focus();
}
function focusKey(ev) {
if (ev.keyCode == 27)
// 27 is the keycode for esc
focusFirst();
}
document.addEventListener("keyup", focusKey, false);
window.addEventListener('load', focusFirst, false);
I’m sure it can be done differently, and more efficiently, so constructive criticism is welcome.
Filed under: Tips n' Tricks , greasemonkey, javascript, textbox focus, workaround
