33

Web ページが読み込まれると、スクリーン リーダー (OS X に付属するものや Windows の JAWS など) がページ全体のコンテンツを読み上げます。しかし、ページが動的で、ユーザーがアクションを実行すると、新しいコンテンツがページに追加されるとします。簡単にするために、 のどこかにメッセージを表示するとします<span>。スクリーン リーダーにその新しいメッセージを読み上げるにはどうすればよいでしょうか?

4

2 に答える 2

37

WAI-ARIA仕様では、スクリーン リーダーが DOM 要素を「監視」できる方法をいくつか定義しています。最もサポートされているメソッドはaria-live属性です。offpoliteassertiveおよびのモードがありますrude。自己主張のレベルが高いほど、スクリーン リーダーが現在話している内容を中断する可能性が高くなります。

以下は、Firefox 3 および Firefox 4.0b9でNVDAを使用してテストされています。

<!DOCTYPE html>
<html>
<head>
  <script src="js/jquery-1.4.2.min.js"></script>
</head>
<body>
  <button onclick="$('#statusbar').html(new Date().toString())">Update</button>
  <div id="statusbar" aria-live="assertive"></div>
</body>

WAI -ARIAロール role="status"role="alert". 非互換性の報告がありましたが、再現できませんでした。

<div id="statusbar" role="status">...</div>
于 2011-01-06T20:29:46.083 に答える
1

これは実際の例です。このアップレベルのマークアップは、リンク付きの順序付けられていないリストから、JS を介して選択メニューに変換されています。実際のコードはもっと複雑で、明らかに全体を含めることはできません。選択メニューをキーボードでアクセスできるようにするために、keypress イベントと onchange イベントを登録し、ユーザーがタブでリストから離れたときに AJAX 呼び出しを開始しました (onchange イベントのタイミングのブラウザーの違いに注意してください)。これはアクセシブルにするための深刻な PITA でしたが、可能です。

  //  HTML

  <!-- select element with content URL -->
  <label for="select_element">State</label>
  <select id="select_element">
     <option value="#URL_TO_CONTENT_PAGE#" rel="alabama">Alabama</option>
  </select>
  <p id="loading_element">Content Loading</p>

  <!-- AJAX content loads into this container -->
  <div id="results_container"></div>


  // JAVASCRIPT (abstracted from a Prototype class, DO NOT use as-is)

  var selectMenu = $('select_element');
  var loadingElement = $('loading_element');
  var resultsContainer = $('results_container');

 // listen for keypress event (omitted other listeners and support test logic)
  this.selectMenu.addEventListener('keypress', this.__keyPressDetector, false);


 /* event callbacks */

 // Keypress listener

  __keyPressDetector:function(e){

    // if we are arrowing through the select, enable the loading element
    if(e.keyCode === 40 || e.keyCode === 38){
        if(e.target.id === 'select_element'){
            this.loadingElement.setAttribute('tabIndex','0');
        }
    }
    // if we tab off of the select, send focus to the loading element
    //  while it is fetching data
     else if(e.keyCode === 9){
        if(targ.id === 'select_element' && targ.options[targ.selectedIndex].value !== ''){            
            this.__changeStateDetector(e);

            this.loadingElement.focus();

        }   
    }
}

// content changer (also used for clicks)
__changeStateDetector:function(e){

    // only execute if there is a state change
    if(this.selectedState !== e.target.options[e.target.selectedIndex].rel){

       // get state name and file path
       var stateName = e.target.options[e.target.selectedIndex].rel;
       var stateFile = e.target.options[e.target.selectedIndex].value;

       // get the state file
       this.getStateFile(stateFile);

       this.selectedState = stateName;

    }
}

getStateFile:function(stateFile){
    new Ajax.Request(stateFile, {
        method: 'get',
        onSuccess:function(transport){      

            // insert markup into container
            var markup = transport.responseText;

            // NOTE: select which part of the fetched page you want to insert, 
            // this code was written to grab the whole page and sort later

            this.resultsContainer.update(markup);

            var timeout = setTimeout(function(){

                // focus on new content
               this.resultsContainer.focus();

            }.bind(this), 150);

        }.bind(this)
    });
}
于 2011-05-05T21:22:18.153 に答える