save things javascript 1

save things javascript

let a = document.createElement('a');
a.href = "data:application/octet-stream,"+encodeURIComponent('"My DATA"');
a.download = 'myFile.json';
a.click(); // we not add 'a' to DOM so no need to remove

Here is what the above code is Doing:
1. Create a new anchor element
2. Set the href attribute to the data you want to download
3. Set the download attribute to the name you want the downloaded file to be called
4. Click the anchor element

Similar Posts