Javascript 空闲超时警告模式在屏幕阅读器上工作
我需要一个当用户空闲时触发的模式的帮助。在我在运行NVDA的Firefox上测试之前,它工作得非常好。使用箭头键和在手机上滑动时,焦点会出现问题。当模式出现,用户使用箭头或滑动时,如果我等待单击,几秒钟后焦点将从“是”按钮反弹到标题。我已将工作示例加载到: 我将空闲时间改为一分钟,并删除了调用服务器以扩展用户会话的部分Javascript 空闲超时警告模式在屏幕阅读器上工作,javascript,jquery,accessibility,screen-readers,Javascript,Jquery,Accessibility,Screen Readers,我需要一个当用户空闲时触发的模式的帮助。在我在运行NVDA的Firefox上测试之前,它工作得非常好。使用箭头键和在手机上滑动时,焦点会出现问题。当模式出现,用户使用箭头或滑动时,如果我等待单击,几秒钟后焦点将从“是”按钮反弹到标题。我已将工作示例加载到: 我将空闲时间改为一分钟,并删除了调用服务器以扩展用户会话的部分 var state ="L"; var timeoutPeriod = 540000; var oneMinute = 60000; var sevenMinutes = 600
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();
}
}
}
可能的解决方案
问题在于VoiceOverSafari,当用户在锚或按钮上滑动时,焦点设置在这些元素上;但是,如果元素是H2,它将不会接收焦点,因为它本机不应该接收任何焦点。为了补偿,我尝试在H2上设置手势事件,但是Voiceover Safari需要时间来读取元素文本或标记出加载,因此它可以防止任何事件触发,这在尝试将焦点设置在从超时功能而不是可单击元素加载的模式时会产生问题。希望苹果将来能解决这个问题