Advertisement
mycar98765

HTML code

Oct 28th, 2022
375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | Source Code | 0 0
  1. <form action="/a" method="POST">
  2. <input
  3. type="text"
  4. value="String"
  5. name="string"
  6. id="filename"
  7.  
  8. />
  9.  
  10. <input type="submit" value="Submit" />
  11. </form>
  12. <script>
  13. document.querySelector("form").addEventListener("submit", (e) => {
  14. e.preventDefault();
  15. const string = document.querySelector("#filename").value;
  16. const element = document.createElement("a");
  17. const file = new Blob([string], { type: "text/plain" });
  18. element.href = URL.createObjectURL(file);
  19. element.download = "test.txt";
  20. document.body.appendChild(element); // Required for this to work in FireFox
  21. element.click();
  22. });
  23. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement