Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to edit a fil with vanilla js

(function () {
    var textFile = null;
  function makeTextFile(text) {
    var data = new Blob([text], {type: 'text/plain'});

    // If we are replacing a previously generated file we need to
    // manually revoke the object URL to avoid memory leaks.
    if (textFile !== null) {
      window.URL.revokeObjectURL(textFile);
    }

    textFile = window.URL.createObjectURL(data);

    return textFile;
  }


  var create = document.getElementById('create');
  var textbox = document.getElementById('textbox');

    //create a click event listener
  create.addEventListener('click', function () {
    var link = document.getElementById('downloadlink');
    link.setAttribute('download', 'info.txt');
    //make the text file
    link.href = makeTextFile(textbox.value);
    link.style.display = 'block';
        //wait for the link to be rendered and then initiate a click to download the file
     window.requestAnimationFrame(function () {
      var event = new MouseEvent('click');
      link.dispatchEvent(event);
      document.body.removeChild(link);
    });
  }, false);

})();
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript variables 
Javascript :: usecontext 
Javascript :: electron vue printer 
Javascript :: vue state 
Javascript :: set range background color google script multiple colors 
Javascript :: elixir guards 
Javascript :: replace in string all occurance jquery 
Javascript :: react particles js 
Javascript :: javascript create class 
Javascript :: this function 
Javascript :: Limit number of selected chekboxes 
Javascript :: react state field declaration 
Javascript :: what is browse router 
Javascript :: Alpine.js: button using @click function not working 
Javascript :: moment.js get time from now 
Javascript :: save js 
Javascript :: convert json to 2d array 
Javascript :: how to upload picture on canvas in react 
Javascript :: electron in webpack 
Javascript :: js create a auto call function inside function 
Javascript :: Jest DOM Manipulation 
Javascript :: map function with params 
Javascript :: difference between js and jsx 
Javascript :: grouped bar charts in chart js 
Javascript :: js animations 
Javascript :: update state in useState hook 
Javascript :: uppercase 
Javascript :: wordpress get plugin url in javascript 
Javascript :: jquery document ready deprecated 
Javascript :: add style by classname javascript 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =