IE's only solution:
function SaveContents(element) {
if (typeof element == "string")
element = document.getElementById(element);
if (element) {
if (document.execCommand) {
var oWin = window.open("about:blank", "_blank");
oWin.document.write(element.value);
oWin.document.close();
var success = oWin.document.execCommand('SaveAs', true, element.id)
oWin.close();
if (!success)
alert("Sorry, your browser does not support this feature");
}
}
}
Required HTML Sample:
<textarea id="myText"></textarea><br />
<button type="button" onclick="SaveContents('myText');">Save</button>
This will save the contents of the specified text field to a file with a name equal to the identifier of the text field.
For other browsers, you can read the following: Does execCommand SaveAs work in Firefox?
Test case and working example: http://jsfiddle.net/YhdSC/1/ (IE only)
: https://support.microsoft.com/en-us/help/281119/internet-explorer-saves-html-content-instead-of-the-active-document
, txt