aboutsummaryrefslogtreecommitdiff
path: root/files/pt-br/web/api/filereader/load_event/index.html
blob: bb33f47c04de1859d4ff882d5d12f4bac754e119 (plain)
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
---
title: FileReader.onload
slug: Web/API/FileReader/load_event
tags:
  - Arquivo
  - Event Handler
  - FileReader
  - Manipulador de eventos
  - Propriedade
translation_of: Web/API/FileReader/onload
original_slug: Web/API/FileReader/onload
---
<p>{{APIRef}}</p>

<p>A propriedade <strong>FileReader.onload</strong> contém um manipulador de eventos (event handler) executado quando o evento de carregamento ({{event('load')}})  é ativado, quando o conteúdo lido com  <a href="/en-US/docs/Web/API/FileReader/readAsArrayBuffer">readAsArrayBuffer</a>, <a href="/en-US/docs/Web/API/FileReader/readAsBinaryString">readAsBinaryString</a>, <a href="/en-US/docs/Web/API/FileReader/readAsDataURL">readAsDataURL</a> ou <a href="/en-US/docs/Web/API/FileReader/readAsText">readAsText</a> fica disponível.</p>

<h2 id="Exemplo">Exemplo</h2>

<pre class="brush:js; line-numbers  language-js"><code class="language-js">// Callback de um &lt;input type="file" onchange="onChange(event)"&gt;
function onChange(event) {
  var file = event.target.files[0];
  var reader = new FileReader();
  reader.onload = function(event) {
    // O arquivo de texto será impresso aqui
    console.log(event.target.result)
  };

  reader.readAsText(file);
}
</code></pre>