简体   繁体   English

aria-live="assertive" role="alert" 不适用于弹出消息

[英]aria-live="assertive" role="alert" not working for pop-up messages

I'm fairly new to ARIA and its functionality with screen readers but I've been trying to figure out why the popup is not being read.我对 ARIA 及其与屏幕阅读器的功能相当陌生,但我一直在试图弄清楚为什么没有读取弹出窗口。 It gets changed when a user clicks a save button which refreshes the page to which a message will appear but then the screen reader doesn't pick up the change in message.当用户单击保存按钮刷新消息将出现的页面时,它会发生变化,但屏幕阅读器不会接收消息中的更改。

From what I've read both aria-live="assertive" and role="alert" should work从我读过的内容来看, aria-live="assertive" 和 role="alert" 都应该有效

I've tried various positions for the tags and aria attributes without luck.我已经尝试了标签和 aria 属性的各种位置,但没有成功。 It's only when I re-click the main content section will it read the alert.只有当我重新单击主要内容部分时,它才会读取警报。

I've tested on IE11 and Chrome (though it really only needs to work on IE)我已经在 IE11 和 Chrome 上测试过(虽然它真的只需要在 IE 上工作)

FYI originally all the < p > were < c:out >仅供参考,最初所有的 < p > 都是 < c:out >

--Main Layout --主要布局

<div class="body-content" style="padding: 4px 0">
 <a id="main_content" tabindex="-1" name="main_content"></a>

<!--                <h1>Main Content</h1> -->
<!--                <p>This is the main content area. -->


<tiles:insertAttribute name="body" />         


</div>

--Include message on every screen --在每个屏幕上包含消息

<jsp:include page="messages.jsp" />

--messages.jsp < --消息.jsp <

div id="errorDiv" aria-live="assertive" class="error" role="alert">
<c:if test="${not empty errors}">
<c:set var="popupErr" value=""/>

        <c:forEach var="error" items="${errors}">

                    <p > ${error}</p>
                <br />
            <c:if test="${popupErr != ''}">
               <c:set var="popupErr">

                            <p > ${popupErr}</p>

                       <c:out value="${popupErr}" escapeXml="false" />\r\n

                   </c:set>
            </c:if>
            <c:set var="popupErr" >

                    <p> ${error}</p>

                <c:out value="${popupErr}" escapeXml="false"/><c:out value="${error}" escapeXml="false" />

            </c:set>
        </c:forEach>

    <c:remove var="errors" scope="session"/>

</c:if>

</div>
<div id="msgDiv" class="message" aria-live="assertive" role="alert">
<c:if test="${not empty message}">
<c:set var="popupMsg" value=""/>

        <c:forEach var="msg" items="${message}">

                <p > ${msg}</p>
                <br />  
            <c:if test="${popupMsg != ''}">
               <c:set var="popupMsg">

                <p > ${popupMsg}</p>

                  <c:out value="${popupMsg}" escapeXml="false"/>\r\n

               </c:set>
            </c:if>

            <c:set var="popupMsg">

                <p > ${popupMsg}</p>

                <c:out value="${popupMsg}" escapeXml="false"/><c:out value="${msg}" escapeXml="false"/>

            </c:set>              
        </c:forEach>


    <c:remove var="message" scope="session"/>

</c:if>

</div>

EDIT:编辑:

This is more of an issue of the page not being re-read once it refreshes after the save click这更多的是页面在点击保存后刷新后不会被重新读取的问题

The question is old, but if someone else stumbles upon it (like me): 这个问题很老,但是如果有人(如我)偶然发现了这个问题:

Your application seems to be rendered on server side, hence is static as far as the browser is concerned (no JS involved changing the DOM at runtime). 您的应用程序似乎在服务器端呈现,因此就浏览器而言是静态的(没有JS涉及在运行时更改DOM)。 I think the following explains why this won't cause screenreaders to announce the message: 我认为以下解释了为什么这不会导致屏幕阅读器宣布此消息:

Assistive technologies will announce dynamic changes in the content of a live region. 辅助技术将宣布实时区域内容的动态变化。 The live region must first be present (and usually empty), so that the browser and assistive technologies are aware of it. 实时区域必须首先存在(通常是空的),以便浏览器和辅助技术可以识别它。 Any subsequent changes are then announced. 然后宣布任何后续更改 https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Live_Regions https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Live_Regions

Simply including an aria-live attribute or a specialized live region role (such as role="alert") in the initial markup as it's loaded will have no effect . 在初始标记中仅包含aria-live属性或专门的实时区域角色(例如role =“ alert”) 就不会生效,因为它已加载。

Or from another source: 或从另一个来源:

Dynamically rendered alerts are automatically announced by most screen readers, and in some operating systems, they may trigger an alert sound. 大多数屏幕阅读器都会自动宣布动态呈现的警报,并且在某些操作系统中,它们可能会触发警报声音。 It is important to note that, at this time, screen readers do not inform users of alerts that are present on the page before page load completes. 重要的是要注意,此时,页面阅读器不会在页面加载完成之前通知用户页面上存在的警报。

https://www.w3.org/TR/wai-aria-practices/#alert https://www.w3.org/TR/wai-aria-practices/#alert

Adding delay to the insert message may help.向插入消息添加延迟可能会有所帮助。 When role="alert" container and message to the container insert altogether screen reader can't distinguish any difference on the container.当 role="alert" 容器和向容器插入的消息一起插入时,屏幕阅读器无法区分容器上的任何差异。 role="alert" message only read when screen reader able to distinguish difference on container. role="alert" 消息仅在屏幕阅读器能够区分容器上的差异时读取。 The best practice is have the container on the DOM and empty and insert the message to the empty container, Hope this help, thanks最佳做法是将容器放在 DOM 上并清空并将消息插入空容器,希望对您有所帮助,谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM