גירסה אחרת שמצאתי שעובדת על בסיס קידוד ישיר
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HTML Editor</title>
<style>
body {
background-color: #f0f0f0; /* Light gray background color */
margin: 0;
padding: 0;
}
/* Container for the editor */
.editor-container {
display: flex;
height: 100vh;
margin: 20px; /* Margin around the entire editor */
}
/* Style for the code input textarea */
#codeInput {
flex: 1;
border: 1px solid #ccc;
padding: 10px;
margin-right: 10px; /* Margin between input and output */
}
/* Style for the output frame */
#outputFrame {
flex: 1;
border: 1px solid #ccc;
padding: 10px;
background-color: #f5f5f5; /* Very light gray background color */
}
</style>
</head>
<body>
<div class="editor-container">
<!-- Left Box for Direct Editing -->
<textarea id="codeInput" contenteditable="true"></textarea>
<!-- Right Box for Code Display -->
<iframe id="outputFrame"></iframe>
</div>
<script>
// Get references to the textarea and the outputFrame
const codeInput = document.getElementById('codeInput');
const outputFrame = document.getElementById('outputFrame');
// Function to update the outputFrame with HTML code from codeInput
function updateOutput() {
const code = codeInput.value;
outputFrame.contentDocument.open();
outputFrame.contentDocument.write(code);
outputFrame.contentDocument.close();
}
// Update the output whenever there is a change in the codeInput
codeInput.addEventListener('input', updateOutput);
// You can initially load some sample code into the codeInput if needed
codeInput.value = 'This text will change the formatting in the right box.';
updateOutput(); // Update the output initially
</script>
</body>
</html>

