Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

saving text in javascript

const downloadToFile = (content, filename, contentType) => {
  const a = document.createElement('a');
  const file = new Blob([content], {type: contentType});
  
  a.href= URL.createObjectURL(file);
  a.download = filename;
  a.click();

	URL.revokeObjectURL(a.href);
};

document.querySelector('#btnSave').addEventListener('click', () => {
  const textArea = document.querySelector('textarea');
  
  downloadToFile(textArea.value, 'my-new-file.txt', 'text/plain');
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript for each loop 
Javascript :: javascript browser tab active 
Javascript :: push function in javascript 
Javascript :: two sum javascript solution 
Javascript :: isotope cdn 
Javascript :: how to run commands in the command prompt using javascript 
Javascript :: display amount with currency for jquery 
Javascript :: how to get on click id in event 
Javascript :: create csv file javascript 
Javascript :: Radom String in Javascript 
Javascript :: simple kick command discord.js v12 
Javascript :: add regexp to antd 
Javascript :: js generate random string of length 
Javascript :: input type number maxlength in react 
Javascript :: run on load js 
Javascript :: offsetheight javascript 
Javascript :: javascript get item in array by id 
Javascript :: laravel link custom javascript file 
Javascript :: javascript callback 
Javascript :: flutter json to class 
Javascript :: timestamp convert moment vue 
Javascript :: javascript randint 
Javascript :: angular library run tests 
Javascript :: update data firestore 
Javascript :: check user by id discord js 
Javascript :: render markdown in nextjs 
Javascript :: while vs do while javascript 
Javascript :: como diminuir quantidade de casas decimais javascript 
Javascript :: javascript tofixed is not a function 
Javascript :: foreach break js 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =