iamnoah / writeCapture

Utility to assist the Ajax loading of HTML containing script tags that use document.write. Mailing List: http://groups.google.com/group/writecapturejs-users
http://iamnoah.github.com/writeCapture
Other
241 stars 38 forks source link

Problems with scripts that do a document.write and access the written elements #26

Closed vincejl closed 13 years ago

vincejl commented 13 years ago

We ran into an issue where an ad was being written with document.write and then tried to access the dom elements written. The writeOnGetElementById option seems to remedy this, but we didn't want to override document.getElementById for performance reasons. What do you guys think of this patch that gives the option to have document.write calls to be written immediately, bypassing the queue?

275c275,276
<       writeOnGet = getOption('writeOnGetElementById',options),  

---
>       writeOnGet = getOption('writeOnGetElementById',options),
>       immediate = getOption('immediateWrites', options),
283,284c284,285
<     doc.write = replacementWrite;
<     doc.writeln = replacementWriteln;

---
>     doc.write = immediate ? immediateWrite : replacementWrite;
>     doc.writeln = immediate ? immediateWriteln : replacementWriteln;
301a303,310
>     }
>     function immediateWrite(s) {
>       var target = $.$(context.target);
>       target.parentNode.innerHTML += s;
>     }
>     function immediateWriteln(s) {
>       var target = $.$(context.target);
>       target.parentNode.innerHTML += s + '\n';
iamnoah commented 13 years ago

I don't see any problems with this. Submit a pull request.

What kind of performance improvements are you seeing?