How to programmatically collapse space in empty div when google ad does not show

前端 未结 4 814
攒了一身酷
攒了一身酷 2021-02-14 12:45

Is there any way to programmatically collapse the empty space that results when a google ad does not show? If so, I would love to see an illustrative example of the same.

<
4条回答
  •  一整个雨季
    2021-02-14 13:23

    The link provided which refers to DFP Premium at this point redirects to documentation for Google Ad Manager, so it's possible this feature is available without DFP Premium at this point.


    Aside from that...
    Usually the existence of an iframe element where you expect it is enough to know whether an ad was put where you were expecting one to be put, or not, in my experience.

    setTimeout(function () {
        if (!document.querySelector('#adcontainer').querySelectorAll('iframe').length > 0) {
            document.querySelector('#adcontainer').remove();
        }
    },1000*2);
    

    As to whether something useful was loaded into that iframe—that isn't something Google is concerned with, so good luck, you'll need it.

提交回复
热议问题