For my own purposes (coughing lazy-load ad script), I overwrite the document.write function to buffer the output of the script, writing it to a div and restoring my own document.write when I finish.
The pseudocode looks something like this:
- save source code document.write
- redefine document.write
- eval and script output buffer
- when the script is running, write a buffer for
- restore your own document.write
The problem arises in the highlighted step - one of the lines in the script declaration creates an iframe and calls
frame.document.write
By doing Firebug, I confirmed that this document.write is native JS code and not my rewritten version.
document.write ? , , document.write .