I need to create a javascript text file that works for all browsers.
I need to create a javascript text file that works for all browsers.
You can use an anchor (element <a>
), and specify the href
with a data URI that contains the content to be downloaded and use the download
attribute to specify the file name.
Unfortunately you can not specify where the file will be stored, or even if it is stored, it depends on the user's decision.
var contenidoDeArchivo = "Hola Mundo!";
var elem = document.getElementById('descargar');
elem.download = "archivo.txt";
elem.href = "data:application/octet-stream,"
+ encodeURIComponent(contenidoDeArchivo);
<a id="descargar">descarga</a>
In addition, there is an API called FileSystem API but it is chrome-specific, so it does not It works for your case.