views:

305

answers:

2

It looks like in most browsers, an <input type="submit"> treats both [spacebar] and [enter] as a click, but an <a> link only treats [enter] as a click.

My app uses a number of links formatted to simulate buttons, so a user that is accustomed to tabbing to a button and pressing [spacebar] will be frustrated.

This bit of jQuery solves the problem:

$("a.Button").die("keypress").live("keypress", function(e) {
    if (e.which == 32) {
        $(this).trigger("click");
        e.preventDefault();
    }
});

My question: Is there a reason not to do this? I'm a little reluctant to override the browser's default behavior on something as basic as this, but since I'm already abusing the link tag to make it look like a button, at least this way I'm not violating the user's expectations any further.

+3  A: 

I think the most important standard to maintain is not the browser's behaviour, but rather the user's expected response.

If you have overriden the display of links by turning them into buttons, the user must be able to treat those "buttons" exactly as they would if it were a real button, otherwise you will confuse and irritate users who have spent years with this "learnt" behaviour.

Andy
A: 

There are the standard usability concerns.

I think 'looks like' is key here. If someone is using a screen reader they will 'see' a link and act appropriately.

If someone has javascript turned off the jquery function (obviously) won't run and they will also get link behaviour.

Obviously you've already done the soul searching(!) over using a link like a button so it is a case of dealing with these two cases - screen reader and non-javascript.

If you can't also simulate the button behaviour (on a link) for these two cases then you will be offering different people a different experience - which is a good reason not to use the function. Either the spacebar should fire every use of these link/buttons or none of them.

amelvin
I disagree for a couple reasons1) Just because standards exist doesn't mean they need be applied in every situation. In this particular case, if he followed your advice, he'd be foregoing *every single user's* expected response, rather than just the very select few who opt out of JS.2) You're also assuming that a user would rather have it work on *no* system, rather than just *some* systems. I can see this being a problem with client-side apps, but on the web, for all practical purposes, web pages almost always render in subtly different ways. User expecation is that this will be the case.
dclowd9901
Fair enough - what about screen readers, are they OK to ignore?
amelvin