1

I'm building my first Firefox extension. So far I am storing the output in local storage, Now I want to download the storage data as a .txt file. My javascript code is:

function saveRecordAsFile() {
   console.log("Record downLoad saveRecordAsFile---");
   if (localStorage.recordData) {
      recordArr = JSON.parse(localStorage.recordData);
      download(JSON.stringify(recordArr), fileNameJMX, 'text/plain');
   }
} 

function download(text, name, type) {   
   var a = document.createElement("a");
   var file = new Blob([text], { type: type });
   a.href = URL.createObjectURL(file);
   a.download = name;  
   a.click();
}

This code works fine in chrome extension. Thanks in advance

Raptor
  • 53,206
  • 45
  • 230
  • 366
Manish
  • 21
  • 1
  • 6

0 Answers0