-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateFile.js
30 lines (28 loc) · 894 Bytes
/
createFile.js
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
function downloadFile(text) {
var data = text;
var fileName = "Prufer.txt";
var file = new Blob([data], {type: "text/plain;charset=utf-8"});
if (window.navigator.msSaveOrOpenBlob) // IE10+
window.navigator.msSaveOrOpenBlob(file, fileName);
else { // Others
var a = document.createElement("a"),
url = URL.createObjectURL(file);
a.href = url;
a.download = fileName;
document.body.appendChild(a);
a.click();
setTimeout(function() {
document.body.removeChild(a);
window.URL.revokeObjectURL(url);
}, 0);
}
}
var openFile = function(event) {
var input = event.target;
var reader = new FileReader();
reader.onload = function(){
var text = reader.result;
generateGraph(text);
};
reader.readAsText(input.files[0]);
};