加载后广告 - 使用appendChild移动带有文本链接广告的IFRAME

发布于 2024-08-31 20:14:32 字数 812 浏览 6 评论 0原文

我已经更改了代码,基本上加载了一个隐藏 div 中的添加页面底部,并附加了一个名为 document.getElementById(xxx).appendChild() 的 onload 事件处理程序,以获取隐藏广告并将其移动到正确的位置我的页面。这很好用。但是,当广告是文本广告时,在我移动广告后,渲染的 Iframe 中没有任何内容。在移动它之前,我做了测试,看看它是什么样子,果然文本链接加载到了 IFRAME 中,但第二次我执行了appendChild 调用来移动包含广告的 div,我似乎丢失了 Iframe 的内容。

任何想法发生了什么

<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>

更新:我认为这里的问题是,在文字广告上,谷歌直接写入 iframe,在其他广告上插入相关的文字链接,它使用 iframe 只指向某些 src。似乎当我执行appendchild时,如果复制完成后没有为iframe设置“src”,则新位置中的iframe不包含任何内容...猜猜它会在src上重新加载?有什么办法解决这个问题吗?

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 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??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情徒 2024-09-07 20:14:32

这应该可以解决问题:

<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>

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>
苏璃陌 2024-09-07 20:14:32

试试这个。如果 Google 放置 IFrame,则放置 IFrame 的内容,否则照常进行:

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';
    }
}

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';
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文