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.
答案 0 :(得分: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>