HOW TO SAVE DATA AS A FILE (E.G. SAVE.TXT) USING JAVASCRIPT - Part 1: Save / Load

Published: 03 March 2021
on channel: ZeroLife
16,588
266

HOW TO SAVE DATA AS A FILE (E.G. SAVE.TXT) USING JAVASCRIPT
Part 1: Save / Load

function func_savedata(data){

var string_data = JSON.stringify(data);
var file = new Blob([string_data], {type:'text'});

var anchor = document.createElement('a');
anchor.href = URL.createObjectURL(file);
anchor.download = 'savefile.txt';
anchor.click();
URL.revokeObjectURL(anchor.href);

}


//======= Alternative =======


function func_savedata(data){

var string_data = JSON.stringify(data);
var file = new File([string_data], 'savefile.txt', {type: 'text;charset=utf-8'})

var anchor = document.createElement('a');
anchor.setAttribute('href', window.URL.createObjectURL(file));
anchor.setAttribute('download', 'savefile.txt')
anchor.click();
URL.revokeObjectURL(anchor.href);

}

PAT:   / rezatahirkheli  
PP: https://www.paypal.com/paypalme/rezat...
BTC: 3EUQBWZKX9Vcwdffd3cUGATQopxrAQQxJ9
LTC: MBXE6hJgxxFYSD8SjmR7sHCHGTqFXmNGoU
GFM: https://gofund.me/7d6500bd


Watch video HOW TO SAVE DATA AS A FILE (E.G. SAVE.TXT) USING JAVASCRIPT - Part 1: Save / Load online without registration, duration hours minute second in high quality. This video was added by user ZeroLife 03 March 2021, don't forget to share it with your friends and acquaintances, it has been viewed on our site 16,588 once and liked it 266 people.