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.
我正在尝试将2个adsense代码添加到一个页面。当我这样做时,只显示一个(第一个定义的)并且页面似乎处于无限加载状态。
Here is the code with example slots and client IDs.
以下是包含示例插槽和客户端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>
If I remove one of these adSense codes than it works. How can I make it work with both codes?
如果我删除其中一个adSense代码而不是它的工作原理。如何使用这两个代码?
2 个解决方案
#1
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:
最后,经过近2个小时的谷歌搜索,我发现了它。我唯一要做的就是为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>
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.
如果只有一个adSense代码,则整数插槽可以正常工作。如果添加另一个,则必须将所有插槽定义为字符串。
Cheers!
#2
1
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
首先,不需要两次show-ad.js文件。其次,show-ad.js似乎在查看一些集合全局变量
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.
当您第二次定义它们时,第一个值被指定,并且第一个值仅显示,因为第二次加载脚本会干扰第一个。
#1
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:
最后,经过近2个小时的谷歌搜索,我发现了它。我唯一要做的就是为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>
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.
如果只有一个adSense代码,则整数插槽可以正常工作。如果添加另一个,则必须将所有插槽定义为字符串。
Cheers!
#2
1
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
首先,不需要两次show-ad.js文件。其次,show-ad.js似乎在查看一些集合全局变量
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.
当您第二次定义它们时,第一个值被指定,并且第一个值仅显示,因为第二次加载脚本会干扰第一个。