WebAIM - Web Accessibility In Mind

E-mail List Archives

Re: onclick and onkeypress

for

From: Andrew Kirkpatrick
Date: Nov 6, 2003 1:17PM


Jared,
Two machines - one made the second alter appear, one didn't.

OSX IE 5.2 (4609) didn't work onclick
OSX IE 5.2.2 (5010.1) did

This is most significantly an issue when the javascript functionality is
something other than opening a new web page. I usually use the page url in
the href attribute as the fallback for that scenario:

<a href="foo.html" onclick="dothis();return false;">

If the user of the page is using a screen reader, the href="#" can be
disorienting -- instead of a link being followed, nothing happens (this is
pretty common on navigation bars with submenus)

On newer browsers you can apply onclick events to elements other than anchor
tags, which helps solve this problem (but causes additional compatibility
issues, of course)

AWK



On 11/6/03 2:34 PM, "Jared Smith" < <EMAIL REMOVED> > wrote:

> I have a problem. When using Javascript, you are not to use mouse
> dependent event handlers. Most recommendations are to use both onclick
> and onkeypress to accomodate both the mouse and keyboard -
> http://www.w3.org/TR/WCAG10-HTML-TECHS/#directly-accessible-scripts
>
> In other words, something like
> <a href="#" onclick="dothis()" onkeypress="dothis()">
>
> However, onkeypress is triggered by pressing ANY alphanumeric key.
> This means that when users are navigating through the page, the event is
> triggered when they press Tab (or 'a' in Opera) while on the link,
> thus triggering the javascript all the time, not just when the Enter
> key is pressed. This makes the page LESS accessible. This would be
> very problematic if the user wants to perform some keyboard action
> (i.e., CTL+P to print) while the link has focus.
>
> Most browsers and screen readers seem to interpret the pressing of the
> Enter key while focused on a link to be the same as onclick (IE on a
> Mac does not).
>
> So, it appears that onkeypress isn't necessary. And if it is, then how
> do you limit the onkeypress event to only the Enter key? But if we
> remove onkeypress, does anybody have a workaround for IE on a Mac,
> which doesn't trigger onclick with the keyboard?
>
> I created at test page at http://acropolis.usu.edu/test.htm to
> demonstrate how onkeypress is problematic in Opera and Netscape and
> how onclick does not suffice for IE on a Mac.
>
> Jared Smith
> WebAIM (Web Accessibility In Mind)
> Center for Persons with Disabilities
> Utah State University
>
>
> ----
> To subscribe, unsubscribe, suspend, or view list archives,
> visit http://www.webaim.org/discussion/
>

--
Andrew Kirkpatrick
CPB/WGBH National Center for Accessible Media
125 Western Ave.
Boston, MA 02134
E-mail: <EMAIL REMOVED>
Web site: ncam.wgbh.org

617-300-4420 (direct voice/FAX)
617-300-3400 (main NCAM)
617-300-2489 (TTY)

WGBH enriches people's lives through programs and services that educate,
inspire, and entertain, fostering citizenship and culture, the joy of
learning, and the power of diverse perspectives.



----
To subscribe, unsubscribe, suspend, or view list archives,
visit http://www.webaim.org/discussion/