Document.write




Here's a possible appication of some relevant parts in the comments above. If you want to test this, put the lines below in a file which you can give any name you want; also create two extra files called external.html and external2.html, and put some content / code inside them:

<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Document.write</title>

<script>
function loadDoc(url) {
var request = new XMLHttpRequest();
request.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.write(request.responseText)
}
}
request.open("GET", url, false);
request.send();
}
function copy_docwritten(to,from)
{
document.getElementById(to).innerHTML=document.getElementById(from).innerHTML
}
function empty_div(which)
{
document.getElementById(which).innerHTML=''
}
</script>

</head>

<body>
<a onclick="copy_docwritten('div1','docwrite1')">load external1</a> <a onclick="copy_docwritten('div2','docwrite2')">load external2</a> <a onclick="empty_div('div1')">empty external1</a> <a onclick="empty_div('div2')">empty external2</a>
<div id="div1"></div>
<div id="div2"></div>

<div style="position: absolute; display: none">
<div id="docwrite1"><script>loadDoc('external.html')</script></div>
<div id='docwrite2'><script>loadDoc('external2.html')</script></div>
</div>

</body>

</html>