开发者

Post Loading ads - using appendChild to move an IFRAME with text link ads

I have changed code around to basically load an add the bottom of the page in a hidden div and attached an onload event handler that called document.getElementById(xxx).appendChild() to take the hidden ad and move it into the right spot in my page. This works GREAT.. however开发者_JS百科 when the ad is a text ad it AFTER i move the ad there is nothing in the rendered Iframe. I did tests to see what it looks like before i move it and sure enough the text links load in the IFRAME but the second i do the appendChild call to move the div that contains the ad i seem to loose the contents of the Iframe.

Any ideas whats going on

<div id="myad" style="display: none;">
    GA_googleFillSlot("MyADSlotName");
</div>

<script>
window.onload = function() {
    // leader board
    document.getElementById('adplaceholder').appendChild(document.getElementById('myAd'));
    document.getElementById('myAd').style.display = '';
</script>

UPDATE: I think what the problem here is that on text ads google writes to the iframe directly inserting the relevant text links where are on other ads it uses the iframe to just point to some src. seems like when i do the appendchild, if there is no "src" set for the iframe after the copy is done the iframe in the new location contains nothing... guess it does a reload on the src? Any way around this??


This should do the trick:

<div id="adsense_empty">placeholder</div>
<div id="adsense_content" style="display: none;">
    <script src="adsense">...</script>
</div>

<script>
function replace( oldel, newel, show ) {
  if ( typeof newel == "string" ) 
    newel = document.getElementById( newel );
  if ( typeof oldel == "string" ) 
    oldel = document.getElementById( oldel );
  if ( newel && oldel )
    oldel.parentNode.replaceChild( newel, oldel );
  if ( show ) 
    newel.style.display = "";
}

window.onload = function() {
    replace( "adsense_empty",  "adsense_content",  true );
    replace( "adsense_empty2", "adsense_content2", true );
    replace( "adsense_empty3", "adsense_content3", true );
};
</script>


Try this. If Google puts an IFrame, put the content of the IFrame, else proceed as usual:

if (document.getElementById('banner_leaderboard'))  
{   
    if (document.getElementById('google_ads_iframe_XXXXX_AllSite_Leaderboard_728x90'))         
    {
        var el1 = document.getElementById('banner_leaderboard');
        el1.innerHTML = document.getElementById('google_ads_iframe_XXXXX_AllSite_Leaderboard_728x90').contentWindow.document.body.innerHTML;
    } 
    else 
    {
        document.getElementById('banner_leaderboard').appendChild(document.getElementById('banner_leaderboard_hidden'));
        document.getElementById('banner_leaderboard_hidden').style.display = 'block';
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜