1//HTML
2<input type='file' accept='image/*' onchange='openFile(event)'><br>
3<img id='output'>
4
5//Javascript
6var openFile = function(event) {
7 var input = event.target;
8
9 var reader = new FileReader();
10 reader.onload = function(){
11 var dataURL = reader.result;
12 var output = document.getElementById('output');
13 output.src = dataURL;
14 };
15 reader.readAsDataURL(input.files[0]);
16}
1 function displayImage(e) {
2 if (e.files[0]) {
3 var reader = new FileReader();
4 reader.onload = function(e) {
5 document.querySelector('#profileDisplay').setAttribute('src', e.target.result);
6 }
7 reader.readAsDataURL(e.files[0]);
8 }
9 }