E-mail List Archives
Re: onclick and onkeypress
From: Jukka K. Korpela
Date: Nov 6, 2003 1:32PM
- Next message: webmaster@theoryxdesign.com: "re[2]: opening new browser windows?"
- Previous message: Jared Smith: "Re: opening new browser windows?"
- Next message in Thread: Theresa Hansen: "Accessible message board"
- Previous message in Thread: Andrew Kirkpatrick: "Re: onclick and onkeypress"
- View all messages in this Thread
On Thu, 6 Nov 2003, Jared Smith 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 -
That's problematic indeed.
> In other words, something like
> <a href="#" onclick="dothis()" onkeypress="dothis()">
That construct introduces a new problem: when JavaScript is disabled, the
construct becomes a link to the start of the page. Is that feasible?
> However, onkeypress is triggered by pressing ANY alphanumeric key.
By the (vague) definition in the HTML spec, by pressing "a 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.
Your conclusion seems to be right.
> 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).
That's probably the way to go: to make user agents handle onclick
reasonably, in a not-so-device-dependent way.
> 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?
By using (JavaScript) code that tries to detect which key was pressed.
But this gets rather complicated and won't work across all JavaScript
implementations.
--
Jukka "Yucca" Korpela, http://www.cs.tut.fi/~jkorpela/
----
To subscribe, unsubscribe, suspend, or view list archives,
visit http://www.webaim.org/discussion/
- Next message: webmaster@theoryxdesign.com: "re[2]: opening new browser windows?"
- Previous message: Jared Smith: "Re: opening new browser windows?"
- Next message in Thread: Theresa Hansen: "Accessible message board"
- Previous message in Thread: Andrew Kirkpatrick: "Re: onclick and onkeypress"
- View all messages in this Thread