Is possible to save JavaScript variable as file? [duplicate]

Yes it is, you could do something like this in HTML5, using the download attribute

function download_txt() {
  var textToSave = document.getElementById('txt').innerHTML;
  var hiddenElement = document.createElement('a');

  hiddenElement.href="data:attachment/text," + encodeURI(textToSave);
  hiddenElement.target="_blank";
  hiddenElement.download = 'myFile.txt';
  hiddenElement.click();
}

document.getElementById('test').addEventListener('click', download_txt);

FIDDLE

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)