Creating Accessible JavaScript
Accessible JavaScript Summary
Article Contents
- Page 1: Overview of Creating Accessible Javascript
- Page 2: JavaScript Event Handlers
- Page 3: Other Issues
- Page 4: JavaScript Alternatives
- Current page: Page 5: Accessible JavaScript Summary
Overview
JavaScript allows developers to add increased interaction, information processing, and control in web-based content. JavaScript can also cause accessibility problems by limiting navigation using a keyboard or assistive technology, presenting content or functionality that is not accessible to assistive technologies, limiting user control over automated content changes, and modifying the normal functionality of the browser. When faced with JavaScript accessibility issues, you must do one of the following:
- Ensure the JavaScript is directly accessible
- Provide an accessible, non-JavaScript alternative
JavaScript is often used to make cosmetic or other content changes that do not affect accessibility. Content written to the page using JavaScript is accessible if:
- Device independent event handlers are used.
- JavaScript enabled content and functionality is accessible to assistive technologies.
- Scripted pages and elements are navigable using a keyboard.
- The normal browser functionality is not modified in a way that may cause confusion or inaccessibility.
- An accessible alternative is provided when JavaScript cannot be made natively accessible.
JavaScript Event Handlers
There are two types of JavaScript event handlers - device dependent and device independent. When implementing event handlers, you must either use a device independent event handler or use multiple device dependent event handlers to accommodate all users. Below is a list of common event handlers and their associated accessibility issues.
onMouseOverandonMouseOut- Device dependent (require the use of a mouse)
- Ensure important content or functionality is not introduced with these event handlers
- Use in conjunction with the
onFocusandonBlurevent handlers to allow keyboard accessibility - Provide an accessible alternative if the content or functionality cannot be made natively accessible
onFocusandonBlur- Device independent (work with both keyboard and mouse)
- Test to ensure that accessibility is not affected
onClickandonDblClick- Device dependent (require the use of a mouse)
onClickis activated by keyboard input when used with links and form elements- There are no device independent or keyboard accessible equivalents to these event handlers
- Functionality and content provide by the
onClickevent handler must also be made accessible onChangeandonSelect- Device independent (work with both keyboard and mouse)
- Functionality and content provide by the
onChangeandonSelectevent handlers must also be made accessible - Drop-down menu navigation items that are triggered with
onChangeare not fully keyboard accessible
Dynamic HTML and Accessibility
Dynamic HTML (DHTML) is a combination of JavaScript and Cascading Style Sheets (CSS). By its very nature, DHTML can present dynamically changing content. DHTML is often triggered by user interactions, such as moving the mouse. When implementing DHTML, you must ensure that the DHTML is triggered in a device independent way and that the content and functionality provided by the DHTML is also accessible.
JavaScript can also be used to write dynamic content to the web page. In most cases, this content is accessible, unless the content is constantly changing or is in any other way interfering with accessibility of the page.
Pop-up Windows
The default behavior of the web browser and certain HTML elements can also be affected by JavaScript. Pop-up windows can be triggered by JavaScript or by JavaScript event handlers. If the user is not alerted to the fact that a pop-up window is opening, they may become confused or disoriented by the unnatural behavior of the Web browser. Further modification of browser windows to remove scroll bars, status bars, menu bars, or tool bars may also cause accessibility problems. Use pop-up windows with care and if they are used, always alert the user to this fact. The user must also be alerted when JavaScript is used to automatically perform browser functions, such as redirecting, refreshing, or automatic scrolling. In all cases, user testing and testing with assistive technologies can provide valuable feedback regarding accessibility of specific JavaScript implementations.
JavaScript Alternatives
There are many ways to provide alternatives to JavaScript. Newer versions of CSS allow much of the behavior of JavaScript to be replicated using CSS alone. Drop-down menus, navigation bars, and interactive images can all be developed without relying on JavaScript. However, the implementation of CSS across browsers and assistive technologies is varied and problematic. When JavaScript itself cannot be made natively accessible, you must provide an accessible alternative. This can be done by replicating or replacing the JavaScript behavior with server-side processing. You can also provide <noscript> content which will be accessible when JavaScript is disabled or not available to the end user.
Standards and Guidelines
The following standards and guidelines apply to JavaScript:
Section 508 of the Rehabilitation Act §1194.22:
- (l): When pages utilize scripting languages to display content, or to create interface elements, the information provided by the script shall be identified with functional text that can be read by assistive technology.
- (n) When electronic forms are designed to be completed on-line, the form shall allow people using assistive technology to access the information, field elements, and functionality required for completion and submission of the form, including all directions and cues.
- (p) When a timed response is required, the user shall be alerted and given sufficient time to indicate more time is required.
W3C Web Content Accessibility Guidelines (WCAG) 1.0:
- 6.3 (Priority 1): Ensure that pages are usable when scripts, applets, or other programmatic objects are turned off or not supported. If this is not possible, provide equivalent information on an alternative accessible page.
- 6.4 (Priority 2): For scripts and applets, ensure that event handlers are input device-independent.
- 6.5 (Priority 2): Ensure that dynamic content is accessible or provide an alternative presentation or page.
- 7.4 (Priority 2): Until user agents provide the ability to stop the refresh, do not create periodically auto-refreshing pages.
- 7.5 (Priority 2): Until user agents provide the ability to stop auto-redirect, do not use markup to redirect pages automatically. Instead, configure the server to perform redirects.
- 8.1 (Priority 2): Make programmatic elements such as scripts and applets directly accessible or compatible with assistive technologies.
- 10.1 (Priority 2): Until user agents allow users to turn off spawned windows, do not cause pop-ups or other windows to appear and do not change the current window without informing the user.
See also:
- W3C Techniques: Direct accessibility of scripts - external link
- JavaScript overview from Jim Thatcher - external link
- Guide to Section 508 Standards on JavaScript from the Access Board - external link
- CSS image rollover technique - external link
- CSS-only drop-down menus - external link and CSS Pull Down Menus - external link
- Discussion on CSS image replacement techniques - external link