2012-11-15 29 views
3

我想添加2个AdSense代码到一个页面。当我这样做时,只显示一个(第一个定义的)并且该页面似乎处于无限载入状态。不能添加多个AdSense代码到一个页面

下面是带有示例插槽和客户端ID的代码。

<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.com/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.com/pagead/show_ads.js"> 
    </script> 
</body> 

如果我删除了这些adSense代码之一,而不是它的作用。我怎样才能使这两个代码工作?

回答

7

最后,经过近两个小时的谷歌搜索,我发现了它。我唯一需要做的就是将报价添加到google_ad_slot变量(哦,我的...)。因此,工作代码如下所示:

<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.com/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.com/pagead/show_ads.js"> 
</script> 

如果只有一个AdSense代码,插槽为整数工作正常。如果添加另一个,则必须将所有插槽定义为字符串

干杯!

1

首先,不需要show-ad.js文件两次。其次,它似乎显示,ad.js着眼于一些设置全局变量

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

当你定义他们第二次的第一值dicarted,而第一个只显示由于加载脚本第二次干涉与第一。

+0

你说得对,问题在于重写在两个横幅中使用的全局变量。我不太确定是否不需要两次show-ad.js。如果你看文件,你会发现一个匿名函数的调用。所以没有办法如何再次调用它。问题仍然存在。如何使它工作? – Frank

+0

我已经搜索了一下,发现禁止在一个页面上拥有多个AdSense帐户。我会小心这个,因为这两个帐户都可以被禁止。 –

+0

我的问题只有一个帐户。是的,你可以添加多个单位。 “每页最多可放置三个广告单元和三个链接单元”。请参阅https://www.google.com/adsense/policies – Frank

相关问题