For my own purposes (cough lazy-loading an ad script), I am overwriting the document.write function in order to buffer the script's output, writing it to a div, and restoring the native document.write when I am done.
The pseudo-code looks something like this:
- save off native code document.write
- redefine document.write
- eval and buffer output of script
- when script is done, write buffer to
- restore native document.write
The problem happens in the bolded step - one of the lines in the ad script creates an iframe, and calls
frame.document.write
Stepping through Firebug, I have verified that this document.write is the native JS code and not my overwritten version.
Is there a way to overwrite document.write for ALL windows and frames? This is a scoping issue, but I'm not sure how to force my document.write to prevail.