-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
28 lines (19 loc) · 783 Bytes
/
Copy pathscript.js
File metadata and controls
28 lines (19 loc) · 783 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const editor = document.getElementById('editor');
const guardarBtn = document.getElementById('guardar');
const limpiarBtn = document.getElementById('limpiar');
guardarBtn.addEventListener('click', () => {
const contenido = editor.value;
const archivo = new Blob([contenido], { type: 'text/plain' });
const enlaceDescarga = document.createElement('a');
enlaceDescarga.download = 'archivo.txt';
enlaceDescarga.href = window.URL.createObjectURL(archivo);
enlaceDescarga.click();
});
limpiarBtn.addEventListener('click', () => {
if (confirm('¿Está seguro de que desea limpiar todo el contenido?')) {
editor.value = '';
}
});
window.addEventListener('load', () => {
editor.value = localStorage.getItem('texto') || '';
});