Katrina wrote:

I am currently reading a book called 'DOM Scripting' by Jeremy Keith. In it, the author suggests not to use onKeyPress as it can lead to accessibility issues when users are tabbing past those elements with that eventHandler.

But at the same time it remains recommended to add both.

HTML Techniques for Web Content Accessibility Guidelines 1.0
http://www.w3.org/TR/WCAG10-HTML-TECHS/#directly-accessible-scripts.

The problem is that onkeypress is not a direct equivalent of onclick. The proper, device independent handler would be onactivate (which, if I remember correctly, is part of the DOM events, but not part of the HTML spec and only supported in IE, of all browsers).

Suggests that tabbing through may cause accessibility issues
http://webstandardsgroup.org/manage/archive.cfm?uid=BAC0AC1F-FFCB-6022-5ECD34D2CF16F906

Yup, that's correct. In principle, it seems right that even hitting TAB should trigger an onkeypress...it's a key, after all; however, this cause issues as noted.

Suggests writing a function that tests for TABbing because Mac browsers don't treat onClick in a device independent way. http://webstandardsgroup.org/manage/archive.cfm?uid=BAC115E5-AA7E-1E4F-82E6DE89F699ED80

Safari does indeed seem to be the only current web browser which doesn't generate an onclick event via the keyboard - anything else treats a keyboard activation (e.g. hitting enter when the focus is on a link, for instance) as onclick.

> Is the recommendation to use onKeyPress and testing for certain keys
> to prevent the TAB activating some onKeyPress code?

So, to accommodate Safari, you should consider using a custom function that only gets triggered if the user has hit enter etc (i.e. not indiscriminately firing for every keypress).

Another technique (if you're applying this to links) could be to programmatically change the href to a javascript pseduo-protocol via the DOM on page load...this will then be fired when the link is activated, no matter how (mouse, keyboard, etc). Purists will frown at this (although I myself frown at the need to write our own event handler, just because Safari doesn't follow the de-facto standard...even Netscape 4 triggers onclick via the keyboard, if I remember correctly...so why not Safari?)

P
--
Patrick H. Lauke
__________________________________________________________
re·dux (adj.): brought back; returned. used postpositively
[latin : re-, re- + dux, leader; see duke.]
www.splintered.co.uk | www.photographia.co.uk
http://redux.deviantart.com
__________________________________________________________
Web Standards Project (WaSP) Accessibility Task Force
http://webstandards.org/
__________________________________________________________
******************************************************
The discussion list for  http://webstandardsgroup.org/

See http://webstandardsgroup.org/mail/guidelines.cfm
for some hints on posting to the list & getting help
******************************************************

Reply via email to