473,785 Members | 2,789 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

OnKeyPress

Kev
I need to make some specific alterations to some JavaScript in webpages in
order to comply with government guidelines on accessibility. Apparently,
whenever the OnClick event is used, it must be accompanied by an alternative
OnKeyPress event. The guidelines are very vague and I am not sure what this
means. I have used the following piece of JavaScript inside the cell of a
table:

onclick="window .open('http://www.etc')

Do I need to add the following?

onkeypress="win dow.open('http://www.etc')
Kev
Jul 23 '05 #1
7 4102
Try
onclick="javasc ript:window.ope n('http://www.etc')"

"Kev" <xj***@ntlworld .com> wrote in message
news:Md******** ******@newsfe5-gui.ntli.net...
I need to make some specific alterations to some JavaScript in webpages in
order to comply with government guidelines on accessibility. Apparently,
whenever the OnClick event is used, it must be accompanied by an alternative OnKeyPress event. The guidelines are very vague and I am not sure what this means. I have used the following piece of JavaScript inside the cell of a
table:

onclick="window .open('http://www.etc')

Do I need to add the following?

onkeypress="win dow.open('http://www.etc')
Kev

Jul 23 '05 #2
Ivo
"Kev" wrote
I need to make some specific alterations to some JavaScript in webpages
in order to comply with government guidelines on accessibility.
Apparently, whenever the OnClick event is used, it must be accompanied
by an alternative OnKeyPress event. The guidelines are very vague and I
am not sure what this means. I have used the following piece of
JavaScript inside the cell of a table:

onclick="window .open('http://www.etc')

Do I need to add the following?

onkeypress="win dow.open('http://www.etc')

Those gov. quidelines want you to provide alternative means for people who
don't click, but do everything with their keyboard. An onkeypress event
handler on the table cell alongside the onclick is however a silly
requirement, as keys cannot be pressed over ordinary page elements. You will
need to write function that catches keypresses on the whole document and
make clear on your page which key (combination) does what, regardless of
whether the (mouse) pointer is over a table cell or not.

function KeyPress(e) {
if (document.all){ e = window.event; key = e.keyCode;}
if (document.layer s){ key = e.which; }
key = String.fromChar Code(key).toLow erCase();
if (e.ctrlKey&&key =="s"){alert("C TRL+S was pressed");retur n false;}
}
document.onkeyd own=KeyPress;

"Steve Karnath" wrote Try
onclick="javasc ript:window.ope n('http://www.etc')"


Sorry Steve, but this neither answers the question nor is it any good
advice. By default already, any value of an event handler like onclick is
interpreted as J(ava)script. The "javascript :" pseudoprotocol is for use in
the place of normal url's, such as in href values, although this is not
part of any standard and not recommended.

HTH
Ivo
Jul 23 '05 #3
Kev wrote:
I need to make some specific alterations to some JavaScript
in webpages in order to comply with government guidelines
on accessibility.
It might have been an idea to mention which government as accessibility
legislation varies across the world.
Apparently, whenever the OnClick event is used, it
must be accompanied by an alternative OnKeyPress event.
The guidelines are very vague and I am not sure what
this means.
This sounds like a requirement to follow the guidelines produced by the
W3C Web Accessibility Initiative: Web Content Accessibility Guidelines
1.0:

<quote>
Guideline 8. Ensure direct accessibility of embedded user interfaces.
....
Checkpoint:
8.1 Make programmatic elements such as scripts and applets
directly accessible or compatible with assistive technologies
[Priority 1 if functionality is important and not presented
elsewhere, otherwise Priority 2.]

Guideline 9. Design for device-independence.

Use features that enable activation of page elements via a variety of
input devices.
Device-independent access means that the user may interact with the user
agent or document with a preferred input (or output) device -- mouse,
keyboard, voice, head wand, or other. If, for example, a form control
can only be activated with a mouse or other pointing device, someone who
is using the page without sight, with voice input, or with a keyboard or
who is using some other non-pointing input device will not be able to
use the form.
....
Generally, pages that allow keyboard interaction are also accessible
through speech input or a command line interface.
....
Checkpoints:
....
9.3 For scripts, specify logical event handlers rather than
device-dependent event handlers. [Priority 2]
....
</quote>

The spirit of these guidelines is that whenever a particular (and
especially an important or even vital) piece of functionality is
triggered with a mouse/pointing device then there should also be a way
of achieving exactly the same using a keyboard. So that the user's
ability to use the resulting page/site/web application does not depend
on the device used to interact with it.

In many cases an onclick handler is already adequate as it can be
triggered with the keyboard. <INPUT type="button|su bmit|refresh"> and <A
href=" ... "> elements facilitate this, but it works because it is
possible to focus these elements using the keyboard (tabbing to them).
I have used the following piece of
JavaScript inside the cell of a table:
When you say "inside the cell of a table" do you mean an onclick
attribute on the TD/TH cell? If so a keyboard alternative is going to be
problematic as TD/TH elements cannot be navigated to/focused using the
keyboard and are not direct receivers of keypress events. TD/TH elements
could intercept keypress events in the capturing or (more realistically,
as it works with IE) the bubbling phase of event propagation but to do
that they must contain an element that can be focused/tabbed to and
receive keyboard events.
onclick="window .open('http://www.etc')
Opening pop-up windows is fundamentally not accessible.
Do I need to add the following?

onkeypress="win dow.open('http://www.etc')


It would be counterproducti ve to open the pop-up window on *any*
keypress event. The user might be trying to activate some other keyboard
navigation/shortcut. In principle you would only want to be triggering
actions with the same key presses as the user would normally use to
activate input buttons and links (which probably means that using (or at
least including) an input button or link would be a better idea).

I can't imagine many circumstances where accessibility would be achieved
by retroactively adding an event-handling attribute to an existing page.
It is really something that warrants thinking about at the design stage.

Richard.
Jul 23 '05 #4
Kev
> It might have been an idea to mention which government as accessibility
legislation varies across the world.
UK.
This sounds like a requirement to follow the guidelines produced by the
W3C Web Accessibility Initiative: Web Content Accessibility Guidelines
1.0:
Yes.
When you say "inside the cell of a table" do you mean an onclick
attribute on the TD/TH cell?
Yes. Here is the page in question. Check it out.
http://www.darlington.gov.uk/Service...anning+Service
/OnlinePlanningR esources.htm

I have 2 more similar pages from which the JavaScript has been removed, but
I am intending to reinstate it if possible:
http://www.darlington.gov.uk/Service...ts+and+Schemes
/Projects%20and% 20Schemes.htm
http://www.darlington.gov.uk/Service...ing%20Services.
htm

I should point out that I am only responsible for the content of around 50
pages of a 2000+ site. I have no control over page layouts and no access to
stylesheets. The use of JavaScript is in danger of being outlawed on this
site and I am fighting to save it.
I can't imagine many circumstances where accessibility would be achieved
by retroactively adding an event-handling attribute to an existing page.


There may well be no benefits. It's just for the sake of abiding by the
rules.

Kev



Jul 23 '05 #5
Kev wrote:
It might have been an idea to mention which government
as accessibility legislation varies across the world.
UK.


The UK DDA is currently an unknown quantity when it comes to web sites
as all of the cases that have been bought to date have been settled out
of court. Though I can understand how a local authority might prefer to
comply anyway (and generally approve).

<snip>
When you say "inside the cell of a table" do you mean
an onclick attribute on the TD/TH cell?
I see. You have a paragraph of text within a TD that you want to
navigate to a URL if clicked upon (and preferably in a new window).
However, that TD is adjacent to a TD containing an image link that
navigates to the same URL. All else being equal (and it is a long way
from being equal as the page stands [1]) that image link would satisfy
the WCAG 1.0 requirement for the necessary functionality to be
accessible through the keyboard. Anyone needing to navigate to the URL
can use that link and view the accompanying text as an explanation of
the link (probably a good idea as some of the images are not
particularly self-explanatory).

Thus you can regard clicking on the text in addition to the link as an
optional extra upon which the viability of the page does not hang.

Those image links could do with some more work; for example the alt text
"ODPM logo: link to ODPM website (new window)" will be of little use to
ordinary members of the UK public as they will not associate the
abbreviation with the Office of the Deputy Prime Minister (and those
reading the alt text will not necessarily be in a position to read the
text from the logo).

My impression of this question (and experience of how web site
accessibility is (miss)handled generally) is that you are trying to get
the page to pass an automated accessibility test. Unfortunately
automated testing is at best a tool that can be used in creating an
accessible web page; passing the tests in no way guarantees that the
results will be accessible, and a completely accessible page can still
fail such a test. Appropriately skilled humans are probably the best
means of achieving accessibility in web pages, and assessing the
results. (Though my judgement would be that retro-fitting accessibility
onto the site as it stands is not viable and it will only really be
achievable through a re-design from the ground up.)

Your own problem demonstrates this admirably because the feature of the
page that is concerning you is not inaccessible to keyboard users (as
such, the pop-up window problem remains). They have the other link to
use when they want to navigate. But your automated testing software will
always see the onclick handler in the TD and can know nothing about what
it does or the fact that it actually does no more than reproduce the
functionality from the adjacent cell.

To placate the machine you would have to lose the onclick handler form
the TD and wrap the text within the cell in a link. Maybe CSS styling
the link into a block element and having it fill the TD (though that
doesn't always work that well on IE browsers) and styling the text to
look like it does now.

Incidentally, it is a mistake to set the cursor for the cell to a hand
using CSS when the functionality is javascript dependent as they are
both optional technologies and independently available and can be
separately disabled/unavailable. A normal javascript design pattern
would add the styling that only made sense in the presence of javascript
using javascript so as not to mislead the user into believing they may
have functionality that they do not have. Also - style="CURSOR: hand" -
is an IE only formulation; using standard CSS would be more in keeping
with the WCAG 1.0 recommendations (and a pragmatic approach is available
to accommodate the older IE versions that do not understand the real CSS
cursor:pointer; ). (and don't bother arguing that everyone uses IE
because accessibility *requires* that a site be usable in more uncommon
UAs).
Yes. Here is the page in question. Check it out.
http://www.darlington.gov.uk/ ...
I wonder what it is about UK local authorities that make them incapable
of producing a web site that is anything approaching good? In its
class - www.darlington.gov.uk - appears to be above average, but when
every line of code on a page speaks of total failure to comprehend the
medium or any of the technologies it uses being above average does no
more than reveal how bad UK local authority sites are on average.

The page starts with an incomplete HTML 4.0 transitional DOCTYPE
declaration, putting all of the browsers that switch modes into quirks
mode. The next element is a SCRIPT, lacking the required type attribute
and invalidity situated outside of even the HTML element (let along the
HEAD or BODY). Then the nonsense really kicks in; the whole page is
marked up in a pseudo-XHTML, but not an XHTML 1.0 appendix C HTML
"compatibil ity" mark-up (which wouldn't make sense with an HTML 4.0
transitional DOCTYPE anyway) but a true nonsense mark-up:-

<LINK rel="stylesheet " type="text/css"
href="/Common/Css/Services.css"/>

- mixed upper and lower case tag names, some contentless elements have
the space before the - /> - and other do not, attributes unknown even in
transitional HTML, etc, etc.

<snip> ... . The use of JavaScript is in danger of
being outlawed on this site and I am fighting to save it.


Javascript and accessibility are not mutually exclusive. But when the
people responsible for a web site clearly don't even comprehend (x?)HTML
it is difficult to see how they could make a valid judgement about
anything that they do on their site.
I can't imagine many circumstances where accessibility would be
achieved by retroactively adding an event-handling attribute to an
existing page.


There may well be no benefits. It's just for the sake of
abiding by the rules.


If by "the rules" you mean the (UK) DDA then the rules require that the
site *be* accessible (assuming that the DDA does apply to web sites
(pending actual legal precedent)), passing accessibility valeting
software produce X is not complying with either the letter of the DDA or
its spirit.

Richard.

[1] Currently the biggest barrier to keyboard operation of your page is
a 'search' submit button that has been given an onclick handler, and had
that handler doubled-up with an onkeypress handler (presumably motivated
by this goal of "accessibility" ). So the user arrives on the page and
starts tabbing through the links and form controls using their keyboard
in an attempt to get to the links that they want to use. They arrive at
this submit button and the onkeypress handler notices that they have not
entered anything in the "search" text field and cancels the default
action, which, for a tab key press, is navigation on to the next
control/link. And shift-tab is also cancelled so they cannot go back
either, not even go back to the "search" text field and to enter
something so that the form validation doesn't cancel their keyboard
navigation attempts. And now they are stuck; end of keyboard
navigation - the page is now fundamentally inaccessible (with an
additional negative impact on the usability of the entire browser).

Of course this has happened because onkeypress has been seen as some
sort of accessibility panacea while the wording of the WCAG 1.0
checkpoint has been disregarded. It says that the event handlers used
should be logical and independent of input device, and forms have an
excellent logical and input device independent event handler that is
ideal for form validation: onsubmit. Unfortunately when web 'developers'
have no comprehension of what they are doing ...
Jul 23 '05 #6
Kev
> My impression of this question (and experience of how web site
accessibility is (miss)handled generally) is that you are trying to get
the page to pass an automated accessibility test.
Exactly.
To placate the machine you would have to lose the onclick handler form
the TD and wrap the text within the cell in a link. Maybe CSS styling
the link into a block element and having it fill the TD (though that
doesn't always work that well on IE browsers) and styling the text to
look like it does now.
I want the whole cell to be the link, not just the text within it. Also,
to change the style of hyperlinked text would be to break another rule.
And stylesheets are off limits.
Incidentally, it is a mistake to set the cursor for the cell to a hand
using CSS when the functionality is javascript dependent as they are
both optional technologies and independently available and can be
separately disabled/unavailable. A normal javascript design pattern
would add the styling that only made sense in the presence of javascript
using javascript so as not to mislead the user into believing they may
have functionality that they do not have. Also - style="CURSOR: hand" -
is an IE only formulation; using standard CSS...
Aside from using CSS, is there any other way to set the cursor? By the
way, I tested it using a different browser and it worked ok.
If by "the rules" you mean the (UK) DDA then the rules require that the
site *be* accessible (assuming that the DDA does apply to web sites
(pending actual legal precedent)), passing accessibility valeting
software produce X is not complying with either the letter of the DDA or
its spirit.
I realise this, but I am primarily concerned about the look and feel of
the webpages for normal users. As long as accessibility is acheieved
suffiently to pass the accreditation, then I don't care if it was
arrived at by the best method or not.
So the user arrives on the page and
starts tabbing through the links and form controls using their keyboard
in an attempt to get to the links that they want to use. They arrive at
this submit button and the onkeypress handler notices that they have not
entered anything in the "search" text field and cancels the default
action, which, for a tab key press, is navigation on to the next
control/link. And shift-tab is also cancelled so they cannot go back
either, not even go back to the "search" text field and to enter
something so that the form validation doesn't cancel their keyboard
navigation attempts. And now they are stuck; end of keyboard
navigation - the page is now fundamentally inaccessible (with an
additional negative impact on the usability of the entire browser).


It seems to tab ok on this page without getting stuck.

Kev
Jul 23 '05 #7
Kev wrote:
My impression of this question (and experience of how web
site accessibility is (miss)handled generally) is that you
are trying to get the page to pass an automated accessibility
test.
Exactly.


I always end up wondering why. If someone has decided to expose a web
site to an automated accessibility test then they must have had some
purpose/motivation. If the point is to avoid violating the (UK) DDA then
passing an automated test alone will not achieve that. Similarly, if the
point is to create an accessible web site then again automated testing
will not achieve that in itself. If the point is to gain a right to
display some accessibility logo then, without the site actually being
accessible, the result is likely to be public ridicule. Otherwise
automated testing without some sort of goal is a waste of resources.
To placate the machine you would ... <snip> I want the whole cell to be the link, not just the text within it.
Also, to change the style of hyperlinked text would be to break
another rule. And stylesheets are off limits.
An alternative way of placating the automatic accessibility checker
would be to add the onclick handler with javascript so that the checking
software would not be able to see it:-

// not executed until after the browsers has processed the mark-up
// for the corresponding, and uniquely IDed, TD element.

if(document.get ElementById){
var tdElement = document.getEle mentById("idOfT dElement");
if(tdElement){
tdElement.oncli ck = function(){ ... };
}
}

<snip> Aside from using CSS, is there any other way to set the cursor?
Yes, using javascript to set the corresponding property of the element's
style object, set the className property of the element to a pre-defined
CSS class, or through the document.styleS heets object (where
implemented).
By the way, I tested it using
a different browser and it worked ok.
Which browser? Opera and Mozilla both show the default arrow pointer.
If by "the rules" you mean the (UK) DDA then the rules
require that the site *be* accessible (assuming that the
DDA does apply to web sites (pending actual legal
precedent)), passing accessibility valeting software
produce X is not complying with either the letter
of the DDA or its spirit.


I realise this, but I am primarily concerned about the
look and feel of the webpages for normal users.
As long as accessibility is acheieved suffiently to pass the
accreditation, then I don't care if it was arrived at by the
best method or not.


The method employed does not appear to be facilitating accessibility at
all (that keypress handler on the submit button is already completely
fatal to it, and, as I said, the problem that the automated testing is
highlighting with the TD onclick is not really a problem for
accessibility as the WCAG checkpoint was already satisfied by the
ability to keyboard navigate to the URL using the adjacent link).

There is a strange (irrational) practice that involves using javascript
to write invalid HTML into otherwise valid document. The document pass
the (x)HTML validator and so the valid (x)HTML logos may be used on the
page (and contractual requirements to produce formally valid web pages
are met). The result is validity in name only. It is easy to
deliberately fool a validator because it is just a machine, and your
automated accessibility test is just as easy to fool.
So the user arrives on the page and starts tabbing through
the links and form controls using their keyboard in an
attempt to get to the links that they want to use. They arrive
at this submit button and the onkeypress handler notices that
they have not entered anything in the "search" text field and
cancels the default action, which, for a tab key press, is
navigation on to the next control/link. ...

<snip>
It seems to tab ok on this page without getting stuck.


How many browsers have your tired it with? It doesn't work on Opera or
Mozilla, and the javascript is trying to cancel the default action from
the keypress event so it should be expected to be a barrier to keyboard
navigation on the page because that is what the script has been designed
to do.

Richard.
Jul 23 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
9780
by: Fred Brown | last post by:
Hi, I want to cancel a certain key in JavaScript. To do so, I catch the event in OnKeyPress and cancel the default: <head> .... function f(evt) { var evt = (evt) ? evt : ((window.event) ? window.event : "") ...
5
4199
by: Albert Wagner | last post by:
I have included a file below that tests onKeyPress in Opera 7.11. I am getting peculiar behavior. When the file is first loaded, pressing the keypad + causes the textarea to get physically larger on the screen, and pressing the keypad - causes the textarea to get physically smaller. I click on the scrollbar then this behaviour stops and subsequent keystrokes are displayed appropriately. Is this some kind of bug in Opera 7.11? ...
2
11129
by: Hasan Ammar | last post by:
Is it possible to set up hotkeys using onkeypress? I know it can be done with the usual alphanumeric keys, but what about function keys? or using ctrl/alt combinations? Does anybody have a tutorial/guide?
3
4793
by: addi | last post by:
I'm looking to perform input validation on an HTML input text element; specifically, I'm looking to prevent anything other than numerical characters from being entered. I've got it working just fine for English characters by using an 'onkeypress' event handler, where basically all that is done is a regular expression check of the character represented by window.event.keyCode against a string containing "0123456789". The problem I'm...
11
31083
by: LilAndy23 | last post by:
How can I use the onKeyPress event handler in Firefox? onKeyPress doesn't seem to fire in Firefox.
2
4180
by: ~toki | last post by:
How can i take the control of the key events in Class2 ? This is the code snipped that i'd tried (after try some others): public class Main : System.Windows.Forms.Form { protected virtual void OnKeyPress(System.Object sender, System.Windows.Forms.KeyPressEventArgs e) { /* Do Nothing */ } } public class Class1 : Main
1
1896
by: Simon Wigzell | last post by:
I'm using a javascript function to interecept all key presses and check for valid character and also check the length of the current string and if it is greater than a sent value, set the focus to the next field. I use this for input for a phone number in the format NNN NNN NNNN it will only allow numbers and will go to the 2nd field when there are 3 characters in the first field and go to the 3rd field when there are 3 characters in the...
3
5175
by: Robert Inder | last post by:
I am struggling to catch kestrokes within an Internet Explorer 6 window. My window happens to be displaying three frames, though I suspect a similar problem would arise with a single document. The "<body.." tag in each frame includes an "onKeyPress" handler to catch and act on key presses. And if I focus the window by clicking on the content of one of the documents, keystrokes are sent to the handler on its "<body..." tag.
1
7496
by: vega80 | last post by:
Hi. I have a problem with assigning an onkeypress-function to dynamically created input-boxes.I want to put the content of an input-field into a tag-list when the user hits enter. This works fine the first time (when the input-field is created in a non-dynamical way). The next input-field is created dynamically by a function that is called when the user hits enter (the previously generated input-field will be hidden). Then I'm trying...
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10327
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10151
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10092
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.