Browse Source

Saves to file on pressing stop now

software_develop
Elmar van Rijnswou 7 years ago
parent
commit
fffb8548ed
  1. 30
      software/files/index.js

30
software/files/index.js

@ -65,7 +65,35 @@ function ch4() {
function buttonStopCallback(){
websocket.send("stop");
var myTextArea = $('#raw_samples');
saveTextAsFile();
}
// https://stackoverflow.com/questions/21479107/saving-html5-textarea-contents-to-file
function saveTextAsFile() {
var textToWrite = document.getElementById('raw_samples').value;
var textFileAsBlob = new Blob([ textToWrite ], { type: 'text/plain' });
var fileNameToSaveAs = "samples.csv";
var downloadLink = document.createElement("a");
downloadLink.download = fileNameToSaveAs;
downloadLink.innerHTML = "Download File";
if (window.webkitURL != null) {
// Chrome allows the link to be clicked without actually adding it to the DOM.
downloadLink.href = window.webkitURL.createObjectURL(textFileAsBlob);
} else {
// Firefox requires the link to be added to the DOM before it can be clicked.
downloadLink.href = window.URL.createObjectURL(textFileAsBlob);
downloadLink.onclick = destroyClickedElement;
downloadLink.style.display = "none";
document.body.appendChild(downloadLink);
}
downloadLink.click();
}
function destroyClickedElement(event) {
// remove the link from the DOM
document.body.removeChild(event.target);
}
function onOpen(evt) {

Loading…
Cancel
Save