<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="utf-8">
<title>WYSIWYG Editor</title>
<script>
let textArea;
function iframeLoad() {
textArea = document.getElementById('WYSIWYG').contentWindow.document;
textArea.write(`
<!DOCTYPE html>
<html>
<body>hello world</body>
</html>
`);
textArea.designMode = 'on';
}
function editCommand(command) {
textArea.execCommand(command, false);
}
</script>
</head>
<body>
<nav>
<h1>Option</h1>
<span>style : </span>
<button onclick="editCommand('bold')">Bold</button>
<button onclick="editCommand('italic')">Italic</button>
<span> </span>
<span>justify : <span>
<button onclick="editCommand('justifyLeft')">Left</button>
<button onclick="editCommand('justifyCenter')">Center</button>
<button onclick="editCommand('justifyRight')">Right</button>
</nav>
<section>
<h2>WYSIWYG Editor</h2>
<iframe onload="iframeLoad()" id="WYSIWYG"></iframe>
</section>
</body>
</html>