Categories
JavaScript Technology

Clever document.write killer

Recovered from the Wayback Machine.

Some ad networks and other script-based entities, such as Google Ads, I believe, use JavaScript document.write to write out the content to our web pages. The organizations use this because they want the content embedded in the page at the point where the item is placed, and there isn’t a lot of control where this can happen.

brothercake at SitePoint has come with a way of eliminating the need for document.write, which is to give the script element an identifier and use it as point of reference where to place the content using the proper DOM functions.

It’s something that should have been obvious, but wasn’t until it was pointed out. As one commenter wrote, a real slapping the head moment.

(via Simon Willison)

Print Friendly, PDF & Email