Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a screen reader to stop reading and read different content

Tags:

I've written a site that uses jQuery to display a modal popup. It essentially covers the entire viewable area of the screen with an overlay, then shows a DIV that contains the actual popup on top of the overlay. One of the requirements for this project has to do with accessibility.

When the page loads, the screen reader starts reading from the top of the page. When a user clicks on a particular link, we display a modal dialog. My question is: how do I interrupt the screen reader's reading of the main portion of the site and tell it to start reading the dialog text?

My modal container is wrapped in a div like this:

<div id="modalcontainer"  tabindex="0" class="popup" role="dialog" aria-labelledby="dialog-label" > 

The jQuery that fires the modal looks like this:

$("#modalLink").click(function (e) {     e.preventDefault();      $("#modalcontainer").center();     $("#modalcontainer").show();     $("#closeBtnLink").focus();     $("#wrapper").attr('aria-disabled', 'true'); }); 

The "closeBtnLink" is the close button within the modal dialog. I would have thought setting the focus on this would instruct the screen reader to start reading from that element.

The "wrapper" element is a SIBLING of the modal dialog. Per a suggestion from another SO user for different reasons, I set "aria-disabled=true" on the wrapper element that contains the entire page. The modal dialog exists as a sibling outside of this container.

My main goal here is to get the screen reader to read the contents of my modal DIV element when they click on a specific link. Any help would be appreciated.

like image 793
Scott Avatar asked Mar 28 '12 03:03

Scott


People also ask

How do I stop screen reader from reading elements?

Methods to Hide from Screen Readers To hide text from a screen reader and hide it visually use the hidden attribute. You can also use CSS to set display: none or visibility: hidden to hide an element from screen readers and visually.

How do I hide text and make it accessible by screen reader?

The conventional way is to use CSS ( display:none; and visibility:hidden; ) or the HTML 5 `hidden` attribute. These properties hide elements not only on the screen, but also for screen reader users. Thus, these elements will not be visible nor vocalized by Assistive technologies (AT).

Do screen readers read hidden content?

Screen readers generally ignore anything with display: none, therefore it is not read out to screen readers. There are various ways of having things hidden visually or non-visually, so we'll run through the cases and techniques for each.

Does a screen reader read all of the text?

Typically, a screen reader will start at the top of a website or document and read any text (including alternate text for images). Some screen readers allow the user to preview information, like the navigation bar or all the headings on a page, and skip the user to the desired section of the page.


1 Answers

This can be accomplished using ARIA role="dialog". you'd have to modify this code for your example, it's vanilla js, so yours will probably be shorter/easier via jQuery.

HTML:

 <div role="dialog" aria-labelledby="myDialog" id="box" class="box-hidden" tabindex="-1">   <h3 id="myDialog">Just an example.</h3>   <button id="ok" onclick="hideDialog(this);" class="close-button">OK</button>   <button onclick="hideDialog(this);" class="close-button">Cancel</button>       </div> 

JavaScript:

 var dialogOpen = false, lastFocus, dialog, okbutton, pagebackground;  function showDialog(el) {     lastFocus = el || document.activeElement;     toggleDialog('show'); } function hideDialog(el) {     toggleDialog('hide'); }  function toggleDialog(sh) {     dialog = document.getElementById("box");     okbutton = document.getElementById("ok");     pagebackground = document.getElementById("bg");      if (sh == "show") {         dialogOpen = true;          // show the dialog          dialog.style.display = 'block';          // after displaying the dialog, focus an element inside it         okbutton.focus();          // only hide the background *after* you've moved focus out of the content that will be "hidden"         pagebackground.setAttribute("aria-hidden","true");      } else {         dialogOpen = false;         dialog.style.display = 'none';         pagebackground.setAttribute("aria-hidden","false");         lastFocus.focus();      } }   document.addEventListener("focus", function(event) {      var d = document.getElementById("box");      if (dialogOpen && !d.contains(event.target)) {         event.stopPropagation();         d.focus();     }  }, true);   document.addEventListener("keydown", function(event) {     if (dialogOpen && event.keyCode == 27) {         toggleDialog('hide');     } }, true);   

source: http://3needs.org/en/testing/code/role-dialog-3.html
more reading: http://juicystudio.com/article/custom-built_dialogs.php

like image 131
albert Avatar answered Sep 17 '22 12:09

albert