downloadInDifferentTextFormat.html 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>OVI - File Downloader</title>
  5. <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
  6. </head>
  7. <body>
  8. <div class="m-3 form-outline w-25 mb-4">
  9. <textarea class="form-control" id="text-input" rows="8" placeholder="Inserire del testo da scaricare in diversi formati"></textarea>
  10. </div>
  11. <button type="button" class="btn btn-outline-primary" id="txt-download-button">Download .txt</button>
  12. <button type="button" class="btn btn-outline-primary" id="doc-download-button">Download .doc</button>
  13. <button type="button" class="btn btn-outline-primary" id="rtf-download-button">Download .rtf</button>
  14. <button type="button" class="btn btn-outline-primary" id="docx-download-button">Download .docx</button>
  15. <script>
  16. const txtDownloadButton = document.getElementById("txt-download-button");
  17. const docDownloadButton = document.getElementById("doc-download-button");
  18. const rtfDownloadButton = document.getElementById("rtf-download-button");
  19. const docxDownloadButton = document.getElementById("docx-download-button");
  20. const textInput = document.getElementById("text-input");
  21. txtDownloadButton.addEventListener("click", function () {
  22. const text = textInput.value;
  23. const blob = new Blob([text], { type: "text/plain" });
  24. const link = document.createElement("a");
  25. link.download = "file.txt";
  26. link.href = URL.createObjectURL(blob);
  27. link.click();
  28. });
  29. docDownloadButton.addEventListener("click", function () {
  30. const text = textInput.value;
  31. const blob = new Blob([text], { type: "application/msword" });
  32. const link = document.createElement("a");
  33. link.download = "file.doc";
  34. link.href = URL.createObjectURL(blob);
  35. link.click();
  36. });
  37. rtfDownloadButton.addEventListener("click", function () {
  38. const text = textInput.value;
  39. const blob = new Blob([text], { type: "application/rtf" });
  40. const link = document.createElement("a");
  41. link.download = "file.rtf";
  42. link.href = URL.createObjectURL(blob);
  43. link.click();
  44. });
  45. docxDownloadButton.addEventListener("click", function () {
  46. const text = textInput.value;
  47. const blob = new Blob([text], { type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document" });
  48. const link = document.createElement("a");
  49. link.download = "file.docx";
  50. link.href = URL.createObjectURL(blob);
  51. link.click();
  52. });
  53. </script>
  54. </body>
  55. </html>