Keep ad scripts that use document.write from breaking your stuff!

With jQuery loadAdScript you can load third party ad network scripts that use document.write into specific containers. The only downside is that the ads will load serially.. but that's necessary to keep them from stepping on each others' toes. And the upside is that your site isn't completely borked!

Sample ads

In this example, the ads are hidden by default, and are only shown when their ad script has finished executing.

The code

$(function(){
// a.js simply calls document.write a few times. It's not great, but it's not
// the end of the world.
$('#a').loadAdScript( 'a.js', function(){
$(this).show(); // When the ad script has loaded, show the ad.
});
// b.js calls document.write and loads another external script that also calls
// document.write. It's starting to get ugly, but that's what third party ad
// networks are all about!
$('#b').loadAdScript( 'b.js', function(){
$(this).show(); // When the ad script has loaded, show the ad.
});
// c.js calls document.write and loads multiple other external scripts that
// also call document.write and load other external scripts. Look out, because
// there's a "web 1.0 document write" party in your page, and everyone's invited!
$('#c').loadAdScript( 'c.js', function(){
$(this).show(); // When the ad script has loaded, show the ad.
});
});