Forum Moderators: open
<html>
<head>
<style type="text/css">
#external {
background: #ccc;
}
</style>
</head>
<body>
<div id="placeholder"></div>
<div id="content">...</div>
<div id="external">
<script>
document.write('External Content');
</script>
</div>
<script>
(function () {
var placeholder = document.getElementById('placeholder'),
external = document.getElementById('external');
placeholder.appendChild(external);
})();
</script>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<title>Some Title</title>
<script type="text/javascript">
//addThisEvent -utility function for setting event listeners
//cross-browser, and preserving 'this' within attachEvent.
//el may be a single html element as a DOM object, or the window object,
//type should be string name of event type ('on' prefix not required, so 'mouseover' or 'onmouseover' works fine)
//fn should be a function to set as an event handler
function addThisEvent(el, type, fn) {
var ename = type.replace(/^on/i, '');
if (el.attachEvent) { //IE
el.attachEvent('on'+ ename, function () {
return fn.call(el, window.event); //fixes IE's fudging of 'this' in attachEvent
});
} else if (el.addEventListener) { //Standard
el.addEventListener(ename, fn, false );
} else {
el["on"+ename] = fn;
}
}
//this variable will receive all strings from within
//document.write calls, which will no longer work
//as we are hijacking document.write below
var STRINGS_TO_WRITE__AAARRRGHHH = '';
document.write = function () {
var i = 0,
a = arguments,
len = a.length;
for (; i < len; i++) {
STRINGS_TO_WRITE__AAARRRGHHH += a[i];
}
};
addThisEvent(window, 'load', function () {
document.getElementById('someDivId').innerHTML = STRINGS_TO_WRITE__AAARRRGHHH;
});
</script>
</head>
<body>
<div id="someDivId" style="background-color:beige;"></div>
<script type="text/javascript">
document.write('hello world<br>', 'I belong in the beige div');
</script>
</body>
</html>