-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.html
More file actions
46 lines (42 loc) · 1.36 KB
/
error.html
File metadata and controls
46 lines (42 loc) · 1.36 KB
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
38
39
40
41
42
43
44
45
46
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Error Reporting</title>
<style>
#errorDisplay {
background-color: #ffe6e6;
color: #d8000c;
padding: 10px;
margin: 20px;
border: 1px solid #d8000c;
border-radius: 5px;
font-family: Arial, sans-serif;
display: none;
}
</style>
</head>
<body>
<h1>My Web App</h1>
<div id="errorDisplay"></div>
<script>
// エラーメッセージを表示する関数
function displayError(message) {
const errorDisplay = document.getElementById('errorDisplay');
errorDisplay.style.display = 'block';
errorDisplay.textContent = `${message}`;
}
// window.onerrorを利用してエラーハンドリング
window.onerror = function (message, source, lineno, colno, error) {
// 詳細なエラー情報をコンソールに出力
console.error('Error caught:', { message, source, lineno, colno, error });
// 一般ユーザー向けのメッセージ表示
displayError(`このエラーメッセージをお知らせください。'${message}' at ${source}:${lineno}`);
};
// 実験的エラー (デモ用)
// 正常なコードではコメントアウトしてください
nonExistentFunction();
</script>
</body>
</html>