Friday, November 3, 2023

Text editor

Text Editor

Text Editor

body { font-family: Arial, sans-serif; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; background-color: #f2f2f2; } .editor { text-align: center; } h1 { color: #333; } textarea { width: 80%; height: 300px; margin: 20px 0; padding: 10px; font-size: 16px; } button { padding: 10px 20px; font-size: 16px; background-color: #3498db; color: #fff; border: none; border-radius: 5px; cursor: pointer; transition: background-color 0.3s; } button:hover { background-color: #2980b9; } function downloadTxtFile() { const textToWrite = document.getElementById('editor').value; const textFileAsBlob = new Blob([textToWrite], { type: 'text/plain' }); const fileNameToSaveAs = 'text_editor_content.txt'; const downloadLink = document.createElement('a'); downloadLink.download = 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 = event => document.body.removeChild(event.target); downloadLink.style.display = 'none'; document.body.appendChild(downloadLink); } downloadLink.click(); }

No comments:

Post a Comment

Today,s tools

  Grammarly: Grammarly is a free grammar and spell checker that helps you write clear, error-free text. It is available as a browser ex...