Let\'s say I have and I need to take the html code within this div, place it inside a file and for
The intended can be achieved with a javascript method. The following function will let you add a personalized name with which you desire to download your text file.
function saveTextAsFile()
{
//inputTextToSave--> the text area from which the text to save is
//taken from
var textToSave = document.getElementById("inputTextToSave").value;
var textToSaveAsBlob = new Blob([textToSave], {type:"text/plain"});
var textToSaveAsURL = window.URL.createObjectURL(textToSaveAsBlob);
//inputFileNameToSaveAs-->The text field in which the user input for
//the desired file name is input into.
var fileNameToSaveAs = document.getElementById("inputFileNameToSaveAs").value;
var downloadLink = document.createElement("a");
downloadLink.download = fileNameToSaveAs;
downloadLink.innerHTML = "Download File";
downloadLink.href = textToSaveAsURL;
downloadLink.onclick = destroyClickedElement;
downloadLink.style.display = "none";
document.body.appendChild(downloadLink);
downloadLink.click();
}
function destroyClickedElement(event)
{
document.body.removeChild(event.target);
}
The above was derived from here.