sticky-kit icon indicating copy to clipboard operation
sticky-kit copied to clipboard

Please Help AdSense disappears

Open osmartbm opened this issue 10 years ago • 25 comments

Hello, I need your help. I'm trying to put some Google DFP Adsense Banners in a sidebar, but when the sticky begins, all the banners disappear!!!.

The banner code is wrapped by

I dont know why, please i need your expertise.

osmartbm avatar Apr 02 '14 03:04 osmartbm

There's nothing displayed after “The banner code is wrapped by” you wrote.

Please use syntax highlight marks (triple backticks) around the code you are quoting:

https://help.github.com/articles/github-flavored-markdown#syntax-highlighting

Update:   Now it looks fine.

Mithgol avatar May 03 '14 18:05 Mithgol

I'm having the exact same problem. It's weird, I couldn't found a possible cause.

I think it could be something about the iframes, because I also have troubles with a "Facebook Like Box" that "reloads" on scrolling when I use stick_in_parent(); on the sidebar where it is...

Any idea on what could be happening?

sarceda avatar May 25 '14 16:05 sarceda

It's definitely something with the iframes. In the case of the Facebook Like Box, when the surrounding DIV is attached (e.g. <div style="position: static; width: 0px; height: 2289px; display: block; vertical-align: baseline; float: right;">) the iFrame is reloaded.

In the case of DFP iframes, they simply load with an empty body.

Edit: I have found similar issues with DOM manipulation, like: https://github.com/ROMB/jquery-dialogextend/issues/8

I think it has something to do with this: "Browser function appendChild only copies DOM parameters and not content. Because of this modifying DOM position of iframe forcing lose it's content. Then browser reloads iframe to restore content."

sarceda avatar May 25 '14 16:05 sarceda

Has anyone found a fix for this?

ehoch avatar Jul 15 '14 13:07 ehoch

Hey guys, I had the same problem...

What I did is adding the css property : -webkit-transform: translateZ(0) to the .sticky class.

It worked like a charm!

LouisDea avatar Oct 19 '14 13:10 LouisDea

I have the same problem and translateZ solution didn't work for me.

ghost avatar Oct 30 '14 16:10 ghost

Same problem, roughly. My AdSense doesn't disappear, but it refreshes the ads when the parent gets stuck, and again when it goes back to original place. Seems like iFrames are reloaded when the plugin does its stuff? Any possible fix? Was previously using another sticky plugin that didn't do this, but it was very big and more complicated.

enfolded avatar Dec 05 '14 08:12 enfolded

I got the same problem and found the solution:

I have to wrap the sticky element with a wrapper, and pass that wrapper as spacer option. As the wrapper is the parent of sticky element, I also need to pass parent option in.

<div class="content">
  <div class="sidebar-wrapper">
    <div class="sidebar">
      This is a sticky column
      <iframe src="google-adsense.html" />
    </div>
  </div>
  <div class="main">
    This is the main column
    <p class="sub">
      Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras tempus id
      leo et aliquam. Proin consectetur ligula vel neque cursus laoreet. Nullam
      dignissim, augue at consectetur pellentesque, metus ipsum interdum
      sapien, quis ornare quam enim vel ipsum.
    </p>
    <p class="sub">
      In congue nunc vitae magna
      tempor ultrices. Cras ultricies posuere elit. Nullam ultrices purus ante,
      at mattis leo placerat ac. Nunc faucibus ligula nec lorem sodales
      venenatis. Curabitur nec est condimentum, blandit tellus nec, semper
      arcu. Nullam in porta ipsum, non consectetur mi. Sed pharetra sapien
      nisl. Aliquam ac lectus sed elit vehicula scelerisque ut vel sem. Ut ut
      semper nisl.
    </p>
  </div>
</div>
<script type="text/javascript">
  $('.sidebar').stick_in_parent({parent: '.content', spacer: '.sidebar-wrapper'});
</script>

The offending code is at https://github.com/leafo/sticky-kit/blob/master/jquery.sticky-kit.coffee#L58 and https://github.com/leafo/sticky-kit/blob/master/jquery.sticky-kit.coffee#L127

trongrg avatar Jan 03 '15 07:01 trongrg

We had the same errors with our specific ads.

So I do not add new wrapper I just set parent and add spacer.

<div id="content">
  <div id="sidebar">
    <div class="inner">
      This is a sticky column
      <iframe src="google-adsense.html" />
    </div>
  </div>
  <div id="main">
    This is the main column
    <p class="sub">
      Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras tempus id
      leo et aliquam. Proin consectetur ligula vel neque cursus laoreet. Nullam
      dignissim, augue at consectetur pellentesque, metus ipsum interdum
      sapien, quis ornare quam enim vel ipsum.
    </p>
    <p class="sub">
      In congue nunc vitae magna
      tempor ultrices. Cras ultricies posuere elit. Nullam ultrices purus ante,
      at mattis leo placerat ac. Nunc faucibus ligula nec lorem sodales
      venenatis. Curabitur nec est condimentum, blandit tellus nec, semper
      arcu. Nullam in porta ipsum, non consectetur mi. Sed pharetra sapien
      nisl. Aliquam ac lectus sed elit vehicula scelerisque ut vel sem. Ut ut
      semper nisl.
    </p>
  </div>
</div>
<script type="text/javascript">
  $('#sidebar > .inner').after('<div class="sticky-content-spacer"/>');
  $('#sidebar > .inner').stick_in_parent({parent: '#content', spacer: '.sticky-content-spacer'});
</script>

bogdangi avatar Jan 05 '15 13:01 bogdangi

I was having this exact problem and inserting a spacer div did the trick. Not 100% sure what the spacer even does (the documentation could be better for it) but glad to know this is the solution. Thanks @trongrg!

martynchamberlin avatar Aug 19 '15 19:08 martynchamberlin

@bogdangi Fixed my issue, thank you!

sitegoals avatar Oct 08 '15 16:10 sitegoals

@bogdangi @trongrg Had the same problem with Facebook Like box iframe and fixed it with your help. Thanks!

ghost avatar Nov 26 '15 07:11 ghost

This method works, my ads no longer disappear, but now my offset_top option does not work. Any ideas?

skillmatic-co avatar Dec 10 '15 23:12 skillmatic-co

Typically ads stop working because by default sticky kit has to move the iframe out and back in to the dom to create the spacer element. If you provide your own spacer element then that step is unnecessary. See the spacer option on http://leafo.net/sticky-kit/#reference

leafo avatar Dec 13 '15 22:12 leafo

@bogdangi @trongrg You guys have no idea how many jobs you save :+1:

ImranBug avatar Dec 23 '15 01:12 ImranBug

In my case spacer: false solved the issue.

davincho avatar Jan 26 '16 09:01 davincho

+1 spacer: false

etoxin avatar Jan 28 '16 03:01 etoxin

+1 spacer: false This worked great for me. Thanks for all the information on this though. This thread saved me a lot of time.

Probablybest avatar Apr 12 '16 10:04 Probablybest

Thanks @trongrg. Specifying 'spacer' and 'parent' solved my issue!

aaaa0441 avatar Apr 29 '16 07:04 aaaa0441

+1 spacer: false

grund3g avatar Jun 29 '16 14:06 grund3g

+1 spacer: false

ricerc1 avatar Jul 27 '16 21:07 ricerc1

+1 spacer: false

meandkareem avatar Jul 29 '16 08:07 meandkareem

+1 spacer: false, thanks

waqarit avatar May 29 '17 11:05 waqarit

spacer: false - works, but for my layout sidebar was jumping left-right because of changing position by plugin.

My sidebars has float: left and float: right. So when it gets to position: fixed my right sidebar jumping left because needs exact value for left. I added this small snippets for this case, maybe it will be useful for somebody with same problem.

First, we have to cache left value of sidebar:

$(".sidebar-2").each(function(){
      var $this = $(this);
      $this.data('fixed', $this.offset().left); // Left value for fixed position 
      $this.data('absolute', $this.position().left); // Left value for absolute (on bottom)
}); 

Then init sticky-kit with event handlers:

$(".sidebar-2").stick_in_parent({ spacer: false })
      .on("sticky_kit:stick sticky_kit:unbottom", function(e) {
      var $el = $(e.target);
      $el.css({ 'left': $el.data('fixed') });
})
    .on("sticky_kit:bottom", function(e) {
        var $el = $(e.target);
        $el.css({ 'left': $el.data('absolute') });
});

This is not a perfect code but can give you main idea and save your time.

chupzzz avatar Jun 13 '17 10:06 chupzzz

Another solution:

If your sticky sidebar has a unique class/ID that distinguishes it from a non-sticky sidebar, then you can just wait for it to appear:

<div id='sidebar_ad'></div>

<script>

function load_sticky_sidebar_ad()
{
	let sidebar_ad_container = document.querySelector('#sidebar_ad');

	if (sidebar_ad_container === null || sidebar_ad_container.closest('.theiaStickySidebar') === null)
	{
		(function(){window.setTimeout(load_sticky_sidebar_ad, 50);})();
	}
	
	else
	{
		googletag.cmd.push(function()
		{
			googletag.display('sidebar_ad');
		});
	}
}

(function(){window.setTimeout(load_sticky_sidebar_ad, 50);})();

</script>

Some modification might be needed depending on how your exact sticky sidebar works, but the general logic there should work for just about any sticky sidebar.

Pikamander2 avatar Jun 30 '20 11:06 Pikamander2