JSFiddle - React, Tailwind, and code Playground
HTML
<textarea id="myText"></textarea><br />
<button type="button" onclick="SaveContents('myText');">Save</button>
JavaScript
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");
}
}
}