I have set up two divs to work with CSS and HTML respectively. Both work as advertised by Codemirror. The issue is when I try to output the values from either of the aforementioned divs to the iframe. I have tried everything I can think of and still nothing. I have searched and searched some more for a solution and nothing I've found has worked. Thanks for your time. Any help is appreciated.
<!doctype html>
<head>
<script src="lib/codemirror.js"></script>
<link rel="stylesheet" href="lib/codemirror.css">
<link rel="stylesheet" href="theme/material.css">
<script src="mode/javascript/javascript.js"></script>
<script src="mode/css/css.js"></script>
<link rel="stylesheet" href="addon/hint/show-hint.css">
<script src="addon/hint/show-hint.js"></script>
<script src="addon/hint/css-hint.js"></script>
<script src="mode/xml/xml.js"></script>
</head>
<body>
<iframe id="output" src=""></iframe>
<div>CSS</div>
<div id="css" class="content" contenteditable></div>
<div>HTML</div>
<div id="html" class="content" contenteditable></div>
<script>
var editor = CodeMirror(document.getElementById("css"), {
mode: "css",
theme: "material",
tabSize: 2,
lineNumbers: true,
extraKeys: {
"Ctrl-Space": "autocomplete"
},
});
</script>
<script>
var editor = CodeMirror(document.getElementById("html"), {
mode: "xml",
htmlMode: true,
theme: "material",
tabSize: 2,
lineNumbers: true,
extraKeys: {
"Ctrl-Space": "autocomplete"
}
});
</script>
<script>
window.onload = function() {
var html = document.getElementById("html"),
css = document.getElementById("css"),
output = document.getElementById("output"),
working = false,
fill = function() {
if (working) {
return false;
}
working = true;
var document = output.contentDocument,
style = document.createElement("style"),
document.body.innerHTML = html.textContent;
style.innerHTML = css.textContent.replace(/\s/g, "");
document.body.appendChild(style);
working = false;
};
html.onkeyup = fill;
css.onkeyup = fill;
}
</script>
</body>
</html>