Don't break the default browser behaviour

Paul Boag

Isn’t it fun how sometimes you think you are being helpful when in fact you are making things far worse? Take for example the small piece of JavaScript this site uses to focus the cursor in the search box.

You would have thought that after more than 10 years in web design I would have learnt my lesson by now. Before you do anything on the web, carefully consider the consequences.

Just trying to help

One day I was loading up Google when I noticed that it had automatically places by cursor in the search box. "Great", I thought, "That saves the user having to select the field before they start typing their keywords. I will have to do the same thing on boagworld". Without another thought, I looked around in Google’s code, found the piece of JavaScript and added it to my site.

The consequences

Over a year later I was writing yesterday’s post and trying to add a link for users to add their comments at the end of the post. I wanted the link to jump directly to the comments block at the bottom of the page. "Easy" I thought, "Just add #Name of ID at the end of the address". I was therefore amazed when for some reason this didn’t work and instead jumped the user halfway down the page for no reason.

It took me some time to realise that the JavaScript was jumping the user back up to the search box, which was about half way down the page. Suddenly, for the first time I was thinking about the consequences of that tiny bit of JavaScript. I realised not only would # links not work but that there were other costs of focusing on the search box. I realised that:

  • I was breaking the tab order for users who couldn’t use the mouse very well.
  • there is a strong possibility that speech browsers will start reading from the position of the cursor rather than the top of the page (I have yet to check this)
  • users at 800×600 are immediately jumped half way down the page rather than viewing it from the top

And the morale of this story…

The morale of this story is that insignificant changes to your site, especially those that mess with the default browser behaviour, can have huge consequences. It is not enough to presume that because it works successfully on another site that it will be okay on yours.