Skip to content

Instantly share code, notes, and snippets.

@kentbrew
Created March 29, 2011 20:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kentbrew/893284 to your computer and use it in GitHub Desktop.
Save kentbrew/893284 to your computer and use it in GitHub Desktop.
Hey, experts? Have I just fixed document.write?
// for increased safety when lazy-loading ads, stats pixels,
// and other scripts that use document.write:
document.write = function () {
if (arguments && arguments[0]) {
var span = document.createElement('SPAN');
span.innerHTML = arguments[0];
var head = document.getElementsByTagName('HEAD')[0];
var body = document.getElementsByTagName('BODY')[0];
if (typeof body === 'object') {
body.appendChild(span);
} else {
if (typeof head === 'object') {
head.appendChild(span);
}
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment