Adsense广告iframe的html正文中有1/3的时间为空

问题描述

我正在尝试使Adsense广告在我的网站上正常运行,但是在某些页面上它们以某种方式加载不一致。广告可能正确地加载了2/3的时间,但有时空间只是保持空白。据我所知,问题不在于没有广告可用。为广告创建了iframe添加data-load-complete="true"标签,但是以某种方式,该广告的html body标签仍为空:<body marginwidth="0" marginheight="0"></body>

<ins class="adsbygoogle" style="display: block; height: auto !important; min-height: 0px !important;" data-ad-client="ca-pub-..." data-ad-slot="6818818970" data-ad-format="auto" data-full-width-responsive="true" data-adsbygoogle-status="done">
    <ins id="aswift_1_expand" style="display:inline-table;border:none;height:280px;margin:0;padding:0;position:relative;visibility:visible;width:900px;background-color:transparent;">
        <ins id="aswift_1_anchor" style="display: block; border: none; height: 280px; margin: 0px; padding: 0px; position: relative; visibility: visible; width: 900px; background-color: transparent; overflow: visible;">
            <iframe id="aswift_1" name="aswift_1" style="left:0;position:absolute;top:0;border:0;width:900px;height:280px;" sandBox="allow-forms allow-popups allow-popups-to-escape-sandBox allow-same-origin allow-scripts allow-top-navigation-by-user-activation" width="900" height="280" frameborder="0" src="" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no" allowfullscreen="true" data-google-container-id="a!1" data-google-query-id="CJf52ubwxewCFQKFgwcdwIoMHw" data-load-complete="true">
                <html class=" yirjomiyii idc0_322">
                    <script type="text/javascript">window["_gaUserPrefs"] = { ioo : function() { return true; } }</script>
                    <head>
                    <script>window.top.postMessage('{"msg_type":"resize-me","key_value":[{"key":"r_nh","value":"0"},{"key":"qid","value":"COCMyfTkxewCFcaadwodDGMDxA"}],"googMsgType":"sth"}','*');</script>
                    <script>window.top.postMessage('{"msg_type":"adsense-labs","key_value":[{"key":"settings","value":"[\\\"ca-pub-...\\\",[[1]]]"}],'*');</script>
                    </head>
                    
                    <body marginwidth="0" marginheight="0"></body>
                </html>
            </iframe>
        </ins>
    </ins>
</ins>

据我了解,通常情况下,如果广告没有加载,则类adsbygoogle的元素甚至都不应包含任何子元素。有谁遇到过HTML正文为空的看似部分加载的广告的问题?有什么想法可能导致这种情况或如何避免这种情况?

解决方法

那是正常的。 AdSense并不总是返回广告。当AdSense未找到任何广告时,它会像您的示例一样返回空的iframe。如果可能的话,应折叠空插槽(注意resize-me消息)。我们不会清理DOM(例如,删除所有ins元素和iframe),因为它不会影响页面的外观。可能会节省一些内存,但是考虑到它是3个额外的DOM元素,因此这些节省很小。