【问题标题】:inserting google advertisements with html使用 html 插入谷歌广告
【发布时间】:2016-11-15 22:26:26
【问题描述】:

早安,

如果这可能是一个重复的问题,我很抱歉,但大多数问题都是关于 Google AdSense 的,我从未使用过。

言归正传,我想知道是否有人知道如何将来自 Google 的广告添加到 HTML 5 网站。

我正在做一个项目。实际的站点文件将在本地驱动器上,但我想在我的页面上插入一个会随机绘制一些 Google Ads 并将它们放置在此部分中的页面。

我不想制作广告或任何类似的东西。假设我有一个 600 像素 x 100 像素块的部分,我希望在运行时“绘制”某个类别的任何广告。

就像我说的页面本身将是本地的,但使用互联网访问页面应该获取这些广告。

提前感谢您的快速回复,如果我过度解释,我想道歉。

【问题讨论】:

  • 首先您应该创建一个 Google AdSense 帐户。然后我很确定一切都已解释,您可以选择广告的宽度。谷歌会给你一个短代码插入你的 HTML 文件,就是这样:)

标签: css html adsense ads


【解决方案1】:

在 HTML 中插入 Google Adsense 非常容易,只需将代码粘贴到 body 标记中,然后使用引导程序或 CSS3 进行定位。

<html>
    <head>
        This is the head of your page
        <title>Example HTML page</title>
    </head>
    <body>
        **Paste your google adsense code inside the body**
        This is the body of your page.
        <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
        <!-- Homepage Leaderboard -->
        <ins class="adsbygoogle"
            style="display:inline-block;width:728px;height:90px"
            data-ad-client="ca-pub-1234567890123456"
            data-ad-slot="1234567890"></ins>
        <script>
            (adsbygoogle = window.adsbygoogle || []).push({});
        </script>
    </body>
</html>

【讨论】:

  • 非常感谢。现在就试试看。
  • 谁能解释一下脚本的作用。为什么我们要推送一个空对象到adsbygoogle
【解决方案2】:

参考Get and copy the ad code(如果您尚未在“如何获取和复制您的广告代码”下创建广告单元)
那就参考Where to paste the ad code in your HTML

解释得很好

【讨论】:

    【解决方案3】:
    <html>
    <head>
    This is the head of your page
    <title>Example HTML page</title>
    </head>
    <body>
    This is the body of your page.
    
    <!-- Ad block -->
    <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
    <ins class="adsbygoogle"
    style="display:inline-block;width:728px;height:90px"
    data-ad-client="ca-pub-1234567890123456"
    data-ad-slot="1234567890"></ins>
    <script>
    (adsbygoogle = window.adsbygoogle || []).push({});
    </script>
    <!-- End of Ad block -->
    
    </body>
    </html>
    

    【讨论】:

    • 这段代码是这个previous answer的副本,代码应该解释一下。请edit您的回复。
    【解决方案4】:

    无法从本地主机或保存的 html 文件加载 Adsense。不起作用。 Google 在展示广告之前会检查该域是否被 Adsense 接受。 因此,当您从本地加载广告时,域属性将丢失。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-16
      • 1970-01-01
      • 1970-01-01
      • 2018-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-20
      相关资源
      最近更新 更多