I have some javascript that I use to write a text file when the user leaves the page. Here is the function:
function handleBrowserCloseButton() {
get_text();
var textToWrite = array;
var textFileAsBlob = new Blob([textToWrite], {type:'text/plain'});
var fileNameToSaveAs = "windows.txt"
var downloadLink = document.createElement("a");
downloadLink.download = fileNameToSaveAs;
downloadLink.innerHTML = "Download File";
downloadLink.href = window.webkitURL.createObjectURL(textFileAsBlob);
downloadLink.click();
}
This works well. The only problem is the name of the file is constant - "windows.txt". What this means is that every time the user leaves the page the file written is "windows(n).txt" where n increases in value by one each time.
Is there a way to have javascript replace the file "windows.txt" instead of creating a new file each time?