iCeR
iCeR

Reputation: 149

How to refresh Google AdSense content?

<div name="googleAd">
 <script type="text/javascript">
            google_ad_client = "ca-pub-xxxxxxxxxxxxx";
            <!--/* BottomRight */-->
            google_ad_slot = "1781127922";
            google_ad_width = 180;
            google_ad_height = 150;
          </script>

          <script name="test" type="text/javascript"
                 src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
          </script>
</div>

I'm going to add Google AdSense to my page and I want to refresh it to view other ads. How can I achieve this one? I'm using XSLT. Thanks for the help.

Upvotes: 2

Views: 2869

Answers (2)

Pepelegal
Pepelegal

Reputation: 91

If the webpage is using jQuery, just implement the code bellow:

$(".adsbygoogle").each(function(i,e){$(e).html($(e).html())});

And, if you want to refresh it each 60 seconds, there is a sample you can try:

var ad_refresher = setInterval(function(){
        $(".adsbygoogle").each(function(i,e){
            $(e).html($(e).html())
        });
    }, 60000);

If the code above was implemented, stop the refresh behaviour with:

clearInterval(ad_refresher);

I suggest you to check Google Adsense documentation if you are allowed to refresh the ads.

Upvotes: 5

user663031
user663031

Reputation:

If you examine the DOM of page with Adsense ads on it, you'll see an iframe. You can find the iframe and then reload it with

iframe.contentWindow.location.reload();

You may have to tweak things to get this to work exactly right.

Upvotes: 1

Related Questions