8. June, 2008

Greasemonkey: focus first input field

Filed under: Web Authoring — frightanic @ 10:21

This blog now resides at It will be discontinued here…

I always get annoyed when I end up at sites where the developer (deliberately?) forgot to set the focus to the relevant input field if there is one. IMDB, as great as its content is, for example fails to give that hang-on-to-your-keyboard experience. I assume that usually you don’t want to switch from keyboard to mouse first in order to put the focus in the search field before you can start typing again.

As a remedy a wrote a little Greasemonkey script that focuses the first “text” input field (text, password, textarea) in the first form if the field is visible i.e. inside the view port.

You may ask yourself whether there are no other scripts available that solve this issue. Sure, there are, but their limits were not acceptable for my needs.

  • Search focus will put focus on the search field regardless of where on the page it is, i.e. the input field could be outside the view port and the page will be scrolled down to it. That’s even worse than using your mouse! Besides, it assumes the input field to be named “search”, “q”, or “keywords” in the HTML source code. How can you make such an assumption?
  • Focus on the search does address the view port issue quite nicely, but also falls short on considering all types of input fields.


  1. The GreaseMonkey script link is broken.

    Comment by Aaron — 21. October, 2010 @ 05:44

  2. impressive (for a noob like me) ty, works well ^.^

    Comment by dwype — 6. November, 2010 @ 02:11

RSS feed for comments on this post.

Blog at

%d bloggers like this: