Asynchronous google ads versus Synchronous

旧街凉风 提交于 2019-12-03 00:58:34

I think what you're looking for is

googletag.pubads().collapseEmptyDivs();

That will hide the empty divs when there are no ads to show. Call it before this line:

googletag.enableServices();

More documentation here, for reference: http://support.google.com/dfp_premium/bin/answer.py?hl=en&answer=1650154

Try this:

<div id='div-gpt-ad-YOURDFPIDGOESHERE-1' style='width:auto; height:auto; margin:0px auto; text-align:center;'>

That should stretch or shrink the div to match the creative dimensions (and even center smaller ads in a bigger adslot)

Add display: none; as in inline style to the containing div.

The collapseEmptyDivs method adds an inline style of display: none; to the parent container div. To prevent the flash of extra whitespace, I first tried adding display: none; as a css style in my stylesheet, but the style wasn't removed when the ads were loaded into the target ad unit space successfully. Moving the display: none; inline seemed to remediated the problem.

well.. you can try a workaround..i am not exactly sure. but you can give it a try..

You have the DIV where your ads will be loaded asynchronously, so you can add an element into it, any dummy item and attach event listener to know when it will be replaced by your ads.

you can listen to DOMNodeRemoved event which is fired when node is removed, and you can resize your div accordingly then .. let me know if it works or any progress in this.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!