-
Notifications
You must be signed in to change notification settings - Fork 0
/
aria-live-onload-500.html
37 lines (32 loc) · 1.26 KB
/
aria-live-onload-500.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>ARIA Live Region on Page Load</title>
</head>
<body>
<h1>ARIA Live Region on Page Load</h1>
<div id="error-container" aria-live="assertive" aria-atomic="true"></div></div>
<script>
let errorHeadingText = 'Login failed:';
let errorMsgText = `Your email or password is incorrect. Please try again, <a href="../account/login?forgot=true">reset your password</a>, or <a href="../account/create">register for a new account.</a>`;
function initialiseLiveRegion() {
let errorContainer = document.querySelector('#error-container');
/* create the level 2 heading which will later receive focus */
let errorHeading = document.createElement('h2');
errorHeading.textContent = errorHeadingText;
errorHeading.setAttribute('tabindex', '-1');
let errorMsg = document.createElement('div');
errorMsg.innerHTML = errorMsgText;
let errorWrapper = document.createElement('div');
errorWrapper.appendChild(errorHeading);
errorWrapper.appendChild(errorMsg);
errorContainer.appendChild(errorWrapper);
errorHeading.focus();
}
document.addEventListener("DOMContentLoaded", () => {
window.setTimeout(initialiseLiveRegion, 500);
});
</script>
</body>
</html>