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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
---
title: 'FileReader: error イベント'
slug: Web/API/FileReader/error_event
tags:
- API
- Error
- Event
- FileReader
- ProgressEvent
- Reference
- Web
- onerror
- イベント
translation_of: Web/API/FileReader/error_event
---
<div>{{APIRef}}</div>
<p><code>error</code> イベントは、エラーによって読み取りが失敗したとき (例えば、ファイルが見つからなかった場合や読み取り可能ではなかった場合) に発生します。</p>
<table class="properties">
<tbody>
<tr>
<th scope="row">バブリング</th>
<td>なし</td>
</tr>
<tr>
<th scope="row">キャンセル可能</th>
<td>いいえ</td>
</tr>
<tr>
<th scope="row">インターフェイス</th>
<td>{{domxref("ProgressEvent")}}</td>
</tr>
<tr>
<th scope="row">イベントハンドラープロパティ</th>
<td>{{domxref("FileReader.onerror")}}</td>
</tr>
</tbody>
</table>
<h2 id="Examples" name="Examples">例</h2>
<pre class="brush: js">const fileInput = document.querySelector('input[type="file"]');
const reader = new FileReader();
function handleSelected(e) {
const selectedFile = fileInput.files[0];
if (selectedFile) {
reader.addEventListener('error', () => {
console.error(`Error occurred reading file: ${selectedFile.name}`);
});
reader.addEventListener('load', () => {
console.error(`File: ${selectedFile.name} read successfully`);
});
reader.readAsDataURL(selectedFile);
}
}
fileInput.addEventListener('change', handleSelected);
</pre>
<h2 id="Specifications" name="Specifications">仕様書</h2>
<table class="standard-table">
<thead>
<tr>
<th scope="col">仕様書</th>
<th scope="col">状態</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{SpecName('File API', '#dfn-error-event')}}</td>
<td>{{Spec2('File API')}}</td>
</tr>
</tbody>
</table>
<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの対応</h2>
<p>{{Compat("api.FileReader.error_event")}}</p>
<h2 id="See_also" name="See_also">関連情報</h2>
<ul>
<li>関連イベント: {{domxref("FileReader.loadstart_event", "loadstart")}}, {{domxref("FileReader.loadend_event", "loadend")}}, {{domxref("FileReader.progress_event", "progress")}}, {{domxref("FileReader.load_event", "load")}}, {{domxref("FileReader.abort_event", "abort")}}</li>
</ul>
|