Google Adsense Error "TagError: adsbygoogle.push() error: No slot size for availableWidth=0 "

I used:

window.onload = function() {
    (adsbygoogle = window.adsbygoogle || []).push({});
}

My site was loading pages in a special way, making heavy use of AJAX, so it had to be this way. Hope this helps someone.

EDIT 2018: I feel like I should mention now that the preferred way to do this would be with window.addEventListener( 'load', ... ), instead of the old method of window.onload = ...


In our case, we had problem displaying two banners but only in Chrome. First banner would not show and it would generate error:

No slot size for availableWidth=0

The second banner would be displayed OK. The problem was not happening in Safari or Firefox. Trying to fix the problem via CSS didn't help.

We solved the problem by changing the:

(adsbygoogle = window.adsbygoogle || []).push({})

to

$(document).ready(function(){(adsbygoogle = window.adsbygoogle || []).push({})})

jQuery is required for above method.


You need to remove the others that are not visible, how I use (jQuery):

$(document).ready(function(){
  var $analyticsOff = $('.adsbygoogle:hidden');
  var $analyticsOn = $('.adsbygoogle:visible');

  $analyticsOff.each(function() {
    $(this).remove();
  });
  $analyticsOn.each(function() {
    (adsbygoogle = window.adsbygoogle || []).push({});
  });
});

Tags:

Javascript

Css