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

javascript - Show Google AdSense ad on modal - Stack Overflow

programmeradmin1浏览0评论

I have a banner AdSense ad on my site. It's kicked off by the code snippet they give me.

In another part of my app, I pop up a modal with some info in it. I'd like to display another ad unit in that modal. I have the following defined in that modal:

<script type="text/javascript"><!--
google_ad_slot = "xxxxx";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src=".js">
</script>

Nothing happens. It's weird to me that you have to include that "show_ads.js" file again. Also, seems like it would overwrite the global js variables that are on the home page that this modal is on top of.

Any ideas how to make this work?

I have a banner AdSense ad on my site. It's kicked off by the code snippet they give me.

In another part of my app, I pop up a modal with some info in it. I'd like to display another ad unit in that modal. I have the following defined in that modal:

<script type="text/javascript"><!--
google_ad_slot = "xxxxx";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication./pagead/show_ads.js">
</script>

Nothing happens. It's weird to me that you have to include that "show_ads.js" file again. Also, seems like it would overwrite the global js variables that are on the home page that this modal is on top of.

Any ideas how to make this work?

Share Improve this question edited Feb 18, 2013 at 22:54 user577808 asked Feb 18, 2013 at 22:30 user577808user577808 2,5274 gold badges22 silver badges31 bronze badges 3
  • How in this modal created / called? – TimWolla Commented Feb 18, 2013 at 22:32
  • Simple modal.$.get("/profiles/" + id, function(data){ $(data).modal({ containerCss: { height: 400 } }); }); – user577808 Commented Feb 18, 2013 at 22:41
  • Even when i define the new ad slot in the console and re-request the script it doesn't work. – user577808 Commented Feb 18, 2013 at 22:42
Add a ment  | 

2 Answers 2

Reset to default 5

What's probably happening is that your modal container element doesn't exist at the time the page was loaded. AdSense is loaded for other ads on your page, and you cannot reload them later.

A mon solution is to load an iframe in your model with an ad in the frame. Unfortunately, this violates the terms of service. It is also against the terms of service to load an ad in a div that is hidden (as this throws off the click-through ratio).

I think your best option is to place the ad in a div that is normally visible, and then position that div on your modal when needed. Not ideal, but the only method I can think of that will keep Google happy.

We tried Brad's solution and other solutions, non worked, simply reloading the ad after 0.1 seconds of showing the Ad worked for us.

PS: just make sure that you don't use a deprecated reload ad function.

发布评论

评论列表(0)

  1. 暂无评论