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

  Рет қаралды 15,146

ZeroLife

ZeroLife

3 жыл бұрын

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: www.paypal.com/paypalme/rezat...
BTC: 3EUQBWZKX9Vcwdffd3cUGATQopxrAQQxJ9
LTC: MBXE6hJgxxFYSD8SjmR7sHCHGTqFXmNGoU
GFM: gofund.me/7d6500bd

Пікірлер: 18
@eazyet2206
@eazyet2206 2 жыл бұрын
Thank you so much search everywhere on how to save to text file and couldn’t find exactly what I needed. Thank you! 🙏
@link123a
@link123a 2 жыл бұрын
Thank you for this excellent tutorial!
@amongus-rq2hb
@amongus-rq2hb Жыл бұрын
This is what i was searching for , Thankyou so much
@jonathansalisbury7551
@jonathansalisbury7551 Жыл бұрын
Thanks for this, just what I was looking for. btw for debugging there is also F12 and the 'Console' tab if you're using a browser and a separate developer text editor.
@edwardmacnab354
@edwardmacnab354 4 ай бұрын
so instead of a url you could store it in a file on your computer using the file path--nice video
@sangmaneewutthip299
@sangmaneewutthip299 3 ай бұрын
Please, tutor more about where recorded files are stored.
@yasirmohammedali
@yasirmohammedali Жыл бұрын
Hi : thank you for the video
@christianjack1250
@christianjack1250 24 күн бұрын
Can user inputs be stored on server in a txt or json file?
@wolfbite369
@wolfbite369 Жыл бұрын
you could inspect elements and see the error in console, it will show the line where it occured, much faster though not every time can point you to the right place because error in one place could make error occure in another place what will missguide you
@faizakazmi255
@faizakazmi255 Жыл бұрын
Can you please make a customized program having two buttons like and dislike ..as soon as the user clicks like the counter is saved in the local file and increments according and shown on screen ..same goes for dislike as well.i just need to show the likes and dislike counterr on screen by Saving the count as soon as the user clicks ..I hope my requirement is cleared thanks
@newsday09
@newsday09 7 ай бұрын
Can you tell haw to make with video?
@vishwajithkr
@vishwajithkr Жыл бұрын
how to save all form datas in one json file in reactJs
@mamthavenkatesh9990
@mamthavenkatesh9990 2 жыл бұрын
Hi, Is it possible to store the same data as file in browser memory? I need to save json data as json file and pass it as a payload to a api. Could this be possible?
@superRe2a
@superRe2a 2 жыл бұрын
In the past, document.cookies were used to store data on the client/user browser memory. The more modern way of doing this is to used LocalStorage or SessionStorage. SessionStorage erases the data as soon as the browser is closed. LocalStorage is forever, unless you put a timer condition on it. There are great tutorials on it online. Try www.w3schools.com/jsref/prop_win_localstorage.asp
@superRe2a
@superRe2a 2 жыл бұрын
You might have to Stringify / Parse your data ... especially json data. It essentially convert them into strings and back into usable data. Check out www.w3schools.com/js/js_json_stringify.asp for more info
@superRe2a
@superRe2a 2 жыл бұрын
You can also try converting it into 'binary string data' or 'base64 string data' and storing it that way.
@AbishakRizal6818
@AbishakRizal6818 Жыл бұрын
Sir if we want to save .html file than can we use same method
@superRe2a
@superRe2a Жыл бұрын
you can try getting the contents of a page by using let x = fetch(url). Once you confirmed that you have the contents of the url/html, then just save x using this method.
Save user form input data in a JavaScript object
7:10
OpenJavaScript
Рет қаралды 38 М.
Read/Write JSON Files with Node.js
10:27
Hey Node
Рет қаралды 86 М.
Универ. 13 лет спустя - ВСЕ СЕРИИ ПОДРЯД
9:07:11
Комедии 2023
Рет қаралды 6 МЛН
버블티로 체감되는 요즘 물가
00:16
진영민yeongmin
Рет қаралды 76 МЛН
The child was abused by the clown#Short #Officer Rabbit #angel
00:55
兔子警官
Рет қаралды 14 МЛН
8.5: Saving Data to JSON File with Node.js - Programming with Text
17:00
The Coding Train
Рет қаралды 224 М.
Saving User Input in JS Objects
8:00
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 199 М.
How to FETCH data from an API using JavaScript ↩️
14:17
Bro Code
Рет қаралды 93 М.
JavaScript FileReader
15:08
Kyle Robinson Young
Рет қаралды 137 М.
Storing Objects with Local Storage in JavaScript
6:58
dcode
Рет қаралды 161 М.
Turning Form Data to CSV files with JavaScript
26:13
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 7 М.
Use JavaScript to Get Value from a Textbox and Display on the Page
7:00
Six Minutes. Smarter.
Рет қаралды 190 М.
Deep Dive into Blobs, Files, and ArrayBuffers
17:42
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 33 М.
Волк подружился с человеком #фильм #кино
1:00
МеткийДик
Рет қаралды 2,4 МЛН
Этот мальчик настоящий герой
1:00
ViralMoments
Рет қаралды 3,6 МЛН