Replace document.write using MooTools


You want to embed a gist on your page. But the CSS that GitHub injects into your page totally screws up your perfectly crafted CSS.

Or maybe you want to use AJAX to load a script that requires the use of document.write. But after teh page has loaded document.write tends to destroy the universe without even asking first!


Replace document.write!

I created a replacement for document.write that saves the arguments and then injects them into the page after the dom is ready.

This is useful for embedding gists on your page since you can use the additional filter option to reject stuff from being written to your page. This would also be really handy for sites that include JavaFX or certain ads or anything that requires the use of document.write on your page. By deferring the injection of that stuff until after the dom is ready your visitors see the page content before any of the extras like Java applets or ads begin to load.

update: Oh yeah, it works after the DOM loads now too. You can optionally set document.write.context to the element you want to inject into. It defaults to document.body. Enjoy!


Thanks to Steida for taking my rough proof-of concept and getting it working much better and faster and to Jan Kassens and random other MooTools pplz for helping refine it.