Monday, September 11, 2023

TEXT EDITOR



Text Editor
body { font-family: Arial, sans-serif; background-color: #f0f0f0; margin: 0; padding: 0; } .editor-container { max-width: 800px; margin: 0 auto; padding: 20px; background-color: #fff; box-shadow: 0 0 10px rgba(0, 0, 0, 0.2); border-radius: 5px; overflow: hidden; } .editor-toolbar { text-align: right; } textarea { width: 100%; padding: 10px; border: 1px solid #ccc; border-radius: 5px; resize: none; } #save-btn { padding: 10px 20px; background-color: #0074d9; color: #fff; border: none; border-radius: 5px; cursor: pointer; } #save-btn:hover { background-color: #0056b3; } document.addEventListener("DOMContentLoaded", function () { const editor = document.getElementById("editor"); const saveBtn = document.getElementById("save-btn"); saveBtn.addEventListener("click", function () { const textToSave = editor.value; if (textToSave.trim() === "") { alert("Cannot save an empty file."); return; } const blob = new Blob([textToSave], { type: "text/plain" }); const url = URL.createObjectURL(blob); const a = document.createElement("a"); a.href = url; a.download = "my_text_file.txt"; a.style.display = "none"; document.body.appendChild(a); a.click(); URL.revokeObjectURL(url); }); });

No comments:

Post a Comment

WORD GENERATOR

Random Word Generator Random Word Generator Click the button below to generate a random w...