-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path404.js
More file actions
21 lines (19 loc) · 713 Bytes
/
404.js
File metadata and controls
21 lines (19 loc) · 713 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
window.onload = function() {
document.querySelectorAll('a').forEach(anchor => {
anchor.addEventListener('click', async function(event) {
event.preventDefault();
const href = anchor.getAttribute('href');
if (!href) return;
try {
const response = await fetch(href);
if (response.ok) {
window.location.href = href;
} else {
window.location.href = '/404.html';
}
} catch (error) {
window.location.href = href;
}
});
});
};