<p>Some original document content.</p>
<button id="replace" type="button">Replace document content</button>Document: writeln() method / notebook
Document: writeln() method
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
const policy = trustedTypes.createPolicy("docPolicy", {
createHTML(string) {
return string
.replace("<script", "<script")
.replace("</script", "</script");
},
});const replace = document.querySelector("#replace");
const oneInput = "<h1>Out with";
const twoInput = "the old</h1>";
const threeInput = "<pre>in with";
const fourInput = "the new!</pre>";
replace.addEventListener("click", () => {
document.open();
document.writeln(policy.createHTML(oneInput));
document.writeln(policy.createHTML(twoInput), policy.createHTML(threeInput));
document.writeln(policy.createHTML(fourInput));
document.close();
});