View Full Version : movin scripts after load

01-31-2009, 11:33 PM

I'm trying to get ads to load at the bottom of the page (so they don't block the page) and them move them to placeholder divs I defined.
The ads are being loaded by calling an ad-server's script which in turn returns an ad-network script.
Some of the scripts have document.write, and some return ifames which makes this quite a problem.

I have tried loading the scripts in divs, and then copying the content of the div to it's placeholder - this resulted in the scripts being called again when placed in the new location (tried it both with taking innerHTML and wil using node.replaceChild)

I even tried creating the script nodes with document.creatElement but then the document.write overrides the page.

any idea how I can get such a thing to work ?

This is an example i tried:

<div id="placeholder"></div>
<div id="deffer-placeholder"><script src=(the source)></script></div>
<script type="text/javascript">
var divs=document.getElementsByTagName("div");
var replacements=new Array();
for(var i=0;i<divs.length;i++){
var deferredContent = divs[i];
if (deferredContent.id.indexOf("defer-") == 0) {
var placeHolder = document.getElementById(deferredContent.id.slice(6));
replacements.push([deferredContent, placeHolder]);
replacements[i][1].parentNode.replaceChild(replacements[i][0], replacements[i][1]);
replacements[i][0].style.display = "block";
return true;