jQuery的追加谷歌的Adsense的div [英] jQuery append Google Adsense to div

查看:297
本文介绍了jQuery的追加谷歌的Adsense的div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在与谷歌的AdSense的问题,是我的jQuery之前加载,杀我的codeS,所以我想我会尝试使用文档准备功能的谷歌Adsense的JavaScript附加到相应的分区,这里的code我试图写:

I'm having issues with google adsense and it loading before my jQuery and killing my codes, so I thought I'd try to append the Google Adsense javascript to the appropriate div using the document ready function, here's the code I'm trying to write:

<script language="javascript" type="text/javascript">
$(document).ready(function(){
    $(".googleBanners").html("<script language='javascript' type='text/javascript'>\n" + "google_ad_client = 'pub-8487967187298044';\n" + "google_ad_slot = '1088799521';\n" + "google_ad_width = 250;\n" + "google_ad_height = 250;\n" + "</" + "script>\n" + "<script language='javascript' src='http://pagead2.googlesyndication.com/pagead/show_ads.js' type='text/javascript'>" + "</" + "script>");
});
</script>

但我不是那么好写的JavaScript / jQuery的,所以如果有人可以帮助我实现这一点,将是非常美妙。

But I'm not so good writing javascript/jQuery so if someone could help me implement this that would be fantastic.

在FF目前我得到的错误是错误:没有定义google_protectAndRun。我不知道这意味着什么,但我猜我写了jQuery code错了..哈哈

The error in FF I'm currently getting is "Error: google_protectAndRun is not defined". I'm not sure what that means, but I'm guessing I've written the jQuery code wrong.. lol

推荐答案

我做到这一点的方法是通过上我想要的广告出现在现场的占位符。

The way I do this is by having a placeholder on the spot I want the ad to appear.

<html>
   <body>
      <div id="googleadgoeshere"></div>
   </body>
</html>

然后放置在一个容器中的google- code。在页面的末尾。

Then place the google-code in a container at the end of the page.

<div id="adsense" style="display:none;">all the google javascript goes here</div>

然后我使用jQuery移动一旦页面加载完成将AdSense code创建iframe中。

I then use jQuery to move the iframe the adsense code creates once the page is done loading.

$(window).load(function(){
    $("#adsense").find("iframe").appendTo("#googleadgoeshere"); 
    $("#adsense").remove();
});

如果你只是尝试移动#adsense格,你会最终有一个空白页。如果你尝试这样做几乎任何其他方式,你将最终获得一个空白页。
谷歌已经建立积极的方式来检查code未移动。如果是这样,你的网页将显示为空白。为什么谷歌已经这样做是超越我,但我发现这种解决方法为我工作...

If you just try to move the #adsense div you will end up with a blank page. If you try to do this most any other way, you will end up with a blank page. Google had built in active ways to check that the code is not moved. If it is, your page will be blank. Why google has done this is beyond me, but I have found this workaround to work for me...

这篇关于jQuery的追加谷歌的Adsense的div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆