This is far fetched, but I know it can and has been done. Do you know how to make an online website/app to open a file? Basicly a website or an app that can read and output a HTML/TXT file. Preferably, I would like to use javascript or jquery, but any language that works on a website will be fine, too. There are online apps like Text for Chrome
that do it. Do you know how? It would be great if you could help me out here. If you have any questions, feel free to ask.
Asked
Active
Viewed 56 times
-2

Filburt
- 17,626
- 12
- 64
- 115

I am a registered user
- 509
- 3
- 6
- 15
-
Can describe _"open a file"_ ? Read user uploaded file ? – guest271314 May 24 '15 at 20:55
-
Yeah, like that. For example, a user uploads a file to the website, the website/app reads the file and puts the file back out on to the screen. – I am a registered user May 24 '15 at 20:57
-
See post. Utilizes `input` , `textarea` elements ; `onchange` event ; `FileReader` – guest271314 May 24 '15 at 21:08
1 Answers
1
Try utilizing <input>
element ; <textarea>
element ; accept="text/plain"
attribute at input
element ; onchange
event attached to input
element ; FileReader()
within onchange
event to output uploaded text file to <textarea>
element
var input = document.getElementById("input");
var output = document.querySelector("[for=input]");
input.onchange = function(e) {
var reader = new FileReader();
reader.onload = function(evt) {
output.textContent = evt.target.result;
};
reader.readAsText(e.target.files[0]);
};
<input id="input" type="file" accept="text/plain" /><br />
<textarea for="input" style="width:300px;height:300px;"></textarea>

guest271314
- 1
- 15
- 104
- 177