I want users of my page to be able to save and load data (single file) which contains images and numerical values.
I've found how to save image
saveImgAs = function (img, fileName) {
a = document.createElement('a');
a.setAttribute('href', img.src);
a.setAttribute("download", fileName);
a.click();
}
and text files
saveTextAsFile = function (textToWrite, fileNameToSaveAs) {
var textFileAsBlob = new Blob([textToWrite], { type: 'text/plain' });
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();
};
destroyClickedElement = function(event) {
document.body.removeChild(event.target);
};
but I don't know how to merge them to one file and how to load that structure back..
Any ideas?