SO fiddle
Test Fiddle mainly for SO Questions
HTML
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/dot-luv/jquery-ui.css">
<div id="ad_468x60"></div>
<script>
// Safe use of document.write:
document.write("<p><b>This was written before the document was parsed</b></p>");
</script>
JavaScript
// Create a closure to keep the old document.write private
(function () {
var oldDW = document.write;
document.write = function (s) {
// Document not parsed yet, allow document.write:
if (document.readyState != "complete")
oldDW.call(document, s);
// Dangerous use, switch to innerHTML instead:
else
document.getElementById("ad_468x60").innerHTML = s;
}
})();
// Unsafe use of document.write
window.onload = function () {
document.write("This was inserted after the document was parsed. No harm done :-)");
}