最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Cannot add multiple adsense codes to one page - Stack Overflow

programmeradmin0浏览0评论

I'm trying to add 2 adsense codes to one page. When I do it only one (the first defined) is shown and the page seems to be in endless loading.

Here is the code with example slots and client IDs.

<body>
    <script type="text/javascript"><!--
        google_ad_client = "ca-pub-xxxxxxxxx"; 
        google_ad_slot = 111111111;
        google_ad_width = 160;
        google_ad_height = 600;
        //-->
    </script>
    <script type="text/javascript"
            src=".js">
    </script>
    <script type="text/javascript"><!--
        google_ad_client = "ca-pub-xxxxxxxxx"; //the same like the first one client
        google_ad_slot = 222222222;
        google_ad_width = 336;
        google_ad_height = 280;
        //-->
    </script>
    <script type="text/javascript"
            src=".js">
    </script>
</body>

If I remove one of these adSense codes than it works. How can I make it work with both codes?

I'm trying to add 2 adsense codes to one page. When I do it only one (the first defined) is shown and the page seems to be in endless loading.

Here is the code with example slots and client IDs.

<body>
    <script type="text/javascript"><!--
        google_ad_client = "ca-pub-xxxxxxxxx"; 
        google_ad_slot = 111111111;
        google_ad_width = 160;
        google_ad_height = 600;
        //-->
    </script>
    <script type="text/javascript"
            src="http://pagead2.googlesyndication./pagead/show_ads.js">
    </script>
    <script type="text/javascript"><!--
        google_ad_client = "ca-pub-xxxxxxxxx"; //the same like the first one client
        google_ad_slot = 222222222;
        google_ad_width = 336;
        google_ad_height = 280;
        //-->
    </script>
    <script type="text/javascript"
            src="http://pagead2.googlesyndication./pagead/show_ads.js">
    </script>
</body>

If I remove one of these adSense codes than it works. How can I make it work with both codes?

Share Improve this question edited Nov 15, 2012 at 13:55 Ben 52.9k36 gold badges132 silver badges154 bronze badges asked Nov 15, 2012 at 13:36 FrankFrank 88912 silver badges25 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

Finally after almost 2 hours of googling I figured it out. Only thing I had to do is to add quotes to google_ad_slot variable (Oh my...). So the working code looks like this:

<body>
<script type="text/javascript"><!--
    google_ad_client = "ca-pub-xxxxxxxxx"; 
    google_ad_slot = "111111111"; // see the quotes
    google_ad_width = 160;
    google_ad_height = 600;
    //-->
</script>
<script type="text/javascript"
        src="http://pagead2.googlesyndication./pagead/show_ads.js">
</script>
<script type="text/javascript"><!--
    google_ad_client = "ca-pub-xxxxxxxxx"; //the same like the first one client
    google_ad_slot = "222222222";
    google_ad_width = 336;
    google_ad_height = 280;
    //-->
</script>
<script type="text/javascript"
        src="http://pagead2.googlesyndication./pagead/show_ads.js">
</script>

If there is just one adSense code, the slot as an integer works fine. If you add another, you must define all slots as strings.

Cheers!

First of all there is no need to require the show-ad.js file twice. Secondly it seems that show-ad.js looks at some set global variables

    google_ad_client = "ca-pub-xxxxxxxxx"; 
    google_ad_slot = 111111111;
    google_ad_width = 160;
    google_ad_height = 600;

When you define them a second time the first values are dicarted, and the first one is only shown because loading the script a second time interferes with the first.

发布评论

评论列表(0)

  1. 暂无评论