javascript - 在屏幕阅读器上工作的空闲超时警告模式

标签 javascript jquery accessibility screen-readers

我需要有关用户空闲时触发的模式的帮助。在我在运行 NVDA 的 Firefox 上测试之前,它工作得很好。使用箭头键和在手机上滑动时出现焦点问题。当模式出现并且用户使用箭头或滑动时,如果我等待单击它,焦点将在几秒钟后从是按钮反弹到标题。我已将工作示例加载到:https://jsfiddle.net/ncanqaam/

我将空闲时间段更改为一分钟,并删除了调用服务器以延长用户 session 的部分。

var state ="L";
var timeoutPeriod = 540000;
var oneMinute = 60000;
var sevenMinutes = 60000;

var lastActivity = new Date();

function getIdleTime() {
    return new Date().getTime() - lastActivity.getTime();
}

//Add Movement Detection
function addMovementListener() {
    $(document).on('mousemove',  onMovementHandler);
    $(document).on('keypress',  onMovementHandler);
    $(document).on('touchstart touchend',  onMovementHandler);
}
//Remove Movement Detection
function removeMovementListener() {
    $(document).off('mousemove', onMovementHandler);
    $(document).off('keypress',  onMovementHandler);
    $(document).off('touchstart touchend',  onMovementHandler);
}

//Create Movement Handler
function onMovementHandler(ev) {
    lastActivity = new Date();
    console.log("Something moved, idle time = " + lastActivity.getTime());
}

function hide() {
    $('#overlayTY').removeClass('opened'); // remove the overlay in order to  make the main screen available again
    $('#overlayTY, #modal-session-timeout').css('display', 'none'); // hide the modal window
    $('#modal-session-timeout').attr('aria-hidden', 'true'); // mark the modal window as hidden
    $('#modal-session-timeout').removeAttr('aria-hidden'); // mark the main page as visible
}

if (state == "L") {
    $(document).ready(function() {
        //Call Event Listerner to for movement detection
        addMovementListener();
        setInterval(checkIdleTime, 5000);
    });

    function endSession() {
        console.log('Goodbye!');
    }

    var modalActive = false;
    function checkIdleTime() {
        var idleTime = getIdleTime();
        console.log("The total idle time is " + idleTime / oneMinute + " minutes.");

        if (idleTime > sevenMinutes) {
            var prevFocus = $(document.activeElement);
            console.log('previously: ' + prevFocus);
            var modal = new window.AccessibleModal({
                mainPage: $('#oc-container'),
                overlay: $('#overlayTY').css('display', 'block'),
                modal: $('#modal-session-timeout')
            });

            if (modalActive === false) {
                console.log(modalActive);
                $('#modal-session-timeout').insertBefore('#oc-container');
                $('#overlayTY').insertBefore('#modal-session-timeout');
                modal.show();
                $('#modal-overlay').removeClass('opened');
                modalActive = true;
                console.log(modalActive);
                console.log('the modal is active');
                $('.js-timeout-refresh').on('click touchstart touchend', function(){
                    hide();
                    modalActive = false;
                    prevFocus.focus();
                    addMovementListener();
                    lastActivity = new Date();
                });

                $('.js-timeout-session-end').on('click touchstart touchend', function(){
                    hide();
                    $('#overlayTY').css('display', 'none');
                    endSession();
                });
            }   
        }
        if ($('#overlayTY').css('display') === 'block'){
            removeMovementListener();
        }

        if (idleTime > timeoutPeriod) {
            endSession();
        }
    }
}

最佳答案

可能的解决方案

  1. 当叠加层可见时禁用 body 上的指针事件。这将限制 body 元素上的键盘/滑动事件
  2. 使用 JS/jQuery 触发对按钮的关注

关于javascript - 在屏幕阅读器上工作的空闲超时警告模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38928796/

相关文章:

javascript - 单击双列表按钮上的移动/删除时如何获取值 - JQUERY

jquery - 使用 jQuery 的 MediaWiki API 没有响应

html - 对于可访问性,禁用的文本框是否比具有角色 ="textbox"的 div 更好?

javascript - 我可以在标题和重要文本上使用 tabindex 吗?

javascript - jQuery,也会在已选择的选项上触发更改

javascript - 如何在下拉选择上运行 jquery 函数

jquery - 想要从以两种方式呈现的页面中获取值(查看和编辑)

JavaScript 可能存在内存泄漏

html - Achecker 链接文本可能没有意义

javascript数组为空且未定义