admin管理员组文章数量:1318156
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 badges2 Answers
Reset to default 7Finally 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.
本文标签: javascriptCannot add multiple adsense codes to one pageStack Overflow
版权声明:本文标题:javascript - Cannot add multiple adsense codes to one page - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742043449a2417654.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论