Created
March 29, 2011 20:59
-
-
Save kentbrew/893284 to your computer and use it in GitHub Desktop.
Hey, experts? Have I just fixed document.write?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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