Is there a way to expand an advert outside of the window width within a GPT (Google Publisher Tag) Safeframe?

前端 未结 1 950
日久生厌
日久生厌 2021-01-22 00:07

I am trying to create an advert that will expand past the side of the page. Using the GPT Safeframe preview tool I am receiving the error \"Invalid EXPAND_REQUEST message. Reaso

相关标签:
1条回答
  • 2021-01-22 00:43

    unfortunately, it's not possible to avoid this behaviour, but i made a workaround, that will "wait", until user is scrolled in place, that is suitable to expand, check this example, that will push banner from bottom, when user have enought space from bottom to expand whole creative:

    <div id="container">
        some lines to make container height<br>
        line<br>
        line<br>
        line<br>
        line<br>
        line<br>
        line<br>
        line<br>
        line<br>
        line<br>
        line<br>
        line<br>
        line<br>
        line<br>
        line<br>
        line<br>
        line<br>
        line<br>
    
        <script>
            // global expanded indicator variable, because API don't have any 
            var expanded = false;
            function expand() {
                var self= $sf.ext.geom().self;
                var config = {
                    push: true,
                    b: 0
                };
    
                var el = document.getElementById('container');
                var containerHeight = el.offsetHeight;
    
                // get height from bottom, that need to be expanded
                var expandBottom = containerHeight - self.h;
    
                // if container is whole inside a SafeFrame, it will not expand
                if(expandBottom < 0) return;
    
                config.b = expandBottom;
                $sf.ext.expand(config);
            }
    
            function expandDelayed(forceExpand) {
                // expand will run just once, or you can force it to run again
                // but collapse first is needed
                if(expanded && forceExpand || !expanded) {
                    $sf.ext.collapse();
                    expanded = false;
                    // there must be some timeout, because .collapse(); method is deplayed somehow
                    setTimeout(expand, 0);
                }
            }
    
            $sf.ext.register(160, 150, function(status, data) {
                // this code will do whole magic of "waiting" for right moment
                if (status === 'geom-update') {
                    expandDelayed();
                }
    
                // change global expanded status
                if (status === 'expanded') {
                    expanded = true;
                }
            });
    
            // init
            expandDelayed();
        </script>
    </div>
    

    hope it helps!

    edit:

    I found better solution here: Unable to access contents of a safeframe returned by Google adx

    0 讨论(0)
提交回复
热议问题