3 ms·
How would you handle waiting simultaneously on multiple scripts that all want to use document.write? I use some ad networks which want to call document.write t
by bemmu 16y ago
How would you handle waiting simultaneously on multiple scripts that all want to use document.write?
I use some ad networks which want to call document.write to insert the ads. First I patch the document.write to a function that writes to the innerhtml for the first ad tag, then after that ad loads I change the function and start loading the next one.
Obviously slower than doing it simultaneously. I suppose I could look at the contents of how the function is called to determine which ad it came from, but did you have some better idea?
- jasondavies 16y agoThat's a tricky one. I haven't tested this, but I think you should be able to listen for the 'load' event on each of the script elements that you inject, and patch document.write differently each time. Let me know how you get on! I plan on doing something like this soon for some of my sites that have AdSense (another document.write culprit).
- toolate 16y agoI just pushed up a class I've been using to do this to github. It's a little rough around the edges, but works in Firefox and IE. I've trialed with the AddThis. http://github.com/joshduck/Injector.js http://github.com/joshduck/Injector.js