Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Screen readers and Javascript

I'm creating a website for a reading service for the blind and visually impaired and I'm using JavaScript (with jQuery) to print some stuff to some of the pages after the page has loaded.

Will the screen reader read the content that is printed to the page with jquery after the page has been loaded?

From this page - "Generally, [screen readers] access the DOM (Document Object Model), and they use browser APIs (Application Programming Interfaces) to get the information they need."

and we know that jQuery is a DOM manipulation library.

So the question becomes.. do screen readers take a copy of the whole DOM and then parse it and read it? Or do they read the DOM, the same one that jQuery works on?

Here's an example of one of the pages that I use JavaScript on. It uses a function that determines what program we have playing over the air and then prints the name of the program and a link to listen to it.

<div id="now-playing-div"></div>

<script>

// invoke the audio-reader javascript library
$( document ).ready( function() {
  var callback = nowPlaying; // catalog, schedule, podcasts, archive or nowPlaying
  var selector = '#now-playing-div';
  makeAudioReaderPage(callback, selector);
});

</script>

So as you can see, if the screen reader doesn't read what the javascript/jquery prints to the #now-playing-div then it will read nothing. Then, we started getting a few emails of confused listeners wondering what happened to the Now Playing link.

So this morning I added this:

<div id='no-js'>Please enable JavaScript to receive this content.</div>

<script>
$( document ).ready( function() {
  $('#no-js').toggle();
});

</script>

But if the problem isn't that JavaScript needs to be enabled (a recent survey shows that 99% of screen-reader users have JavaScript enabled) then the problem is not solved and is made even worse because now the screen reader user would think that JavaScript is not enabled.

What to do??

like image 240
Dan Mantyla Avatar asked May 25 '16 16:05

Dan Mantyla


People also ask

Can screen readers read JavaScript?

They don't parse the HTML directly but an accessible tree view of a document. This means that if your browser understands javascript, your screenreader will. That because, your screen reader will not access the DOM directly on the load of the page, but will interact with the Accessibility API provided by your browser.

Why might using JavaScript be an accessibility problem?

However, JavaScript can also introduce accessibility issues. These issues may include: Navigation. Inability or difficulty navigating using a keyboard or assistive technology.

What can screen readers not read?

Unicode characters also include miscellaneous symbols and pictographs. Like astrological, musical, political and religious symbols. Yes, Unicode characters might look interesting and stand out visually. But they are inaccessible to screen reader users.


2 Answers

You can test this without needing to know how screen readers parse the DOM. I offer this answer primarily because you haven't offered any code to test ("some stuff to some of the pages" is not code to test) and your example doesn't provide enough context.

  • Install NVDA, a free screen reader for Windows.
  • If on a Mac, turn on VoiceOver.
  • If on Ubuntu / Gnome, install Orca
  • Download and run a trial of JAWS.
  • If on iOS, turn on VoiceOver.
  • If on Android, turn on TalkBack.
  • Heck, try Narrator on Windows.

There are plenty of tutorials to get you up and running. Here are a couple:

  • A video overview of NVDA.
  • Get a list of keyboard shortcuts for many screen readers.

Then, if you find that your script modifies the DOM after the screen reader has already parsed it, explore ARIA live regions and then look at browser support.

Finally, your example above about detecting if script is enabled doesn't actually need script to work if you use the <noscript> element:

<noscript>
 <p>
 Please enable JavaScript to receive this content.
 </p>
</noscript>

If a browser has script enabled, this will not render (which is good). This does not, however, address cases where the script block you want to show fails for other reasons (network lag, bugs, etc). More on <noscript>

Since you say you are "creating a website for a reading service for the blind and visually impaired" the onus is really on you to learn the tools and how to test with them.

like image 177
aardrian Avatar answered Oct 17 '22 02:10

aardrian


"Generally, [screen readers] access the DOM (Document Object Model), and they use browser APIs (Application Programming Interfaces) to get the information they need."

Modern screen readers use the Accessibility API. They do not have to know anything about Javascript, or about the real DOM and HTML (with the sole exception of ChromeVox).

For that reason, the same screenreader will be used to consult Internet with your favorite browser, to write mail with your favorite program (Thunderbird, Outlook, ...) or to play a flash player game, as long as those programs provide the correct informations to their Accessibility API. They don't parse the HTML directly but an accessible tree view of a document.

This means that if your browser understands javascript, your screenreader will. That because, your screen reader will not access the DOM directly on the load of the page, but will interact with the Accessibility API provided by your browser.

Now, evidently, if your screenreader reads the content before it was modified by javascript, it won't have any clue about modifications made by javascript. For that matter, you can use aria-live attribute.

This is a short abstract, but the following article can give you more informations about the parsing of the DOM by screen readers: Why accessibility APIs matter

like image 4
Adam Avatar answered Oct 17 '22 00:10

Adam