Membuat save txt dengan html Css dan javascript


Save txt dengan javascript html

 Membuat save txt dengan html dan javascript

<html> <head> <title>Save Text File</title> </head> <body> <h1>Save Text File</h1> <form action=""> <textarea id="textarea" cols="30" rows="10">Write your text to save</textarea> <button type="button" onclick="saveTextAsFile()">Save Text File</button> </form> <script type="text/javascript"> function saveTextAsFile() { var textToWrite = document.getElementById("textarea").value; var textFileAsBlob = new Blob([textToWrite], { type: 'text/plain' }); var fileNameToSaveAs = "mySavedText.txt"; var downloadLink = document.createElement("a"); = fileNameToSaveAs; downloadLink.innerHTML = "Download File"; if (window.webkitURL != null) { // Chrome allows the link to be clicked // without actually adding it to the DOM. downloadLink.href = window.webkitURL.createObjectURL(textFileAsBlob); } else { // Firefox requires the link to be added to the DOM // before it can be clicked. downloadLink.href = window.URL.createObjectURL(textFileAsBlob); downloadLink.onclick = destroyClickedElement; = "none"; document.body.appendChild(downloadLink); }; } function destroyClickedElement(event) { document.body.removeChild(; } </script> </body> </html>

Posting Komentar

Lebih baru Lebih lama

Formulir Kontak