Hi everybody, hope I have your attention this time...
Some of you propably know the problem with advertisment distributors and their excessive use of document.write() On the one hand, you tried to call advertisement as soon as possible, to have it shown as soon as possible. On the other hand, when you do that, an the advertisement library calls another remote script, which lags, your whole document lags. So you begin writing hacks to load advertisement at the end of your document, and traversing it to the positions, where it is to be shown. But your still bound to the document loading, since you cannot allow document.write() to be called afterwards... So I didn't invent the wheel when I thought about rewriting document.write() One of these days I finally found an implementation of rewriting document.write() which I actually got working: document.write = (function () { for (var i = 0; i < arguments.length; i++) { $('#someId').append(arguments[i]); } }); And hey, there can come as many document.write() calls in any remote script, which is called in scripts, which were called themselves via document.write(), they are all append smoothly, without blocking any of my page rendering. (I even have another little trick, with which the whole advertisment calling is parallel to my page parsing) I have found the holy grail, or didn't I? Yes, as you propably already saw at first glance, I define the point where to append inside my function definiton. So what the hack, just rewrite as a closure, and before calling the nex ad change the id, where it is to be appendend. Unfortunatelly there is one big problem, I cannot get my fingers on. jQuery's append() internally uses evalScript() to evaluate script- tags, found in the appending-String. For script-tags with src- attribute, it uses an ajax-call, with it's options set false for async! But alas, it seems this is the point a cannot, for remote scripts, jQuery's ajax()-calls always seem to be asynchronous. So when calling an advertisement, then resetting the div, document.write() should append to and then calling the seconf ad, I'm not really synchronous any longer, the first written script-src are still called, while the second ad starts calling it's own html-string- with scripts. So when the first script-src is ready, an the script inside is being evaluated, the new set position for document.write already is set, and all is written to the latter. Example (test.js and test2.js, vividly calling document.write() themselves) setIdDocumentWriteShouldAppendTo('#Id1'); document.write('<script src='http://remote.url/test.js'></script>); setIdDocumentWriteShouldAppendTo('#Id2'); document.write('<script src='http://remote.url/test2.js'></script>); the second document.write is called, before test.js is finished loading... There it is, your typical raise condition. Hope any one can understand gebrabbel... ;) greetings Benedikt