【问题标题】:Load Double Click for Publishers adverts using Jquery UI tabs使用 Jquery UI 标签加载 DFP 广告
【发布时间】:2013-04-11 01:53:47
【问题描述】:

我真的想要一个将广告从 DFP 渲染到 ajax jquery UI 选项卡的解决方案。

我到处研究过,谷歌没有提供任何支持或文档。我有一个我一直在试验的示例 js 类。到目前为止,我一生都无法在标签加载时获得要呈现的广告。

我已经使用这个 gem https://github.com/digineo/google_dfp 加载了所有必要的依赖项。但我真的希望能够从 ajax 加载的内容中动态加载广告?

class @ScorecardViewController

  constructor: (@element) ->
    $(document).bind "tabsload", =>
      @tabLoaded()

  getGraphData: ->


  tabLoaded: ->
    @panel = $(CricTabsController.getLoadedPanel(@element))

    @loadAdverts()

    graphs = @panel.find(".match-graph").map (index, value) ->
      $(value).attr("id")
    @getGraphData() if graphs.length

  loadAdverts: ->
    tags = @panel.find("div.google-dfp")

    googletag.cmd.push( ->
      tags.each ->
        $this = $(@)
        googleAdSlot = googletag.defineSlot( $this.data('unit'), [$this.width(), $this.height()], $this.attr("id")).addService(googletag.pubads())
        googletag.pubads().enableAsyncRendering()
        googletag.enableServices()
        googletag.display($this.attr("id"))
        googletag.callback()
    )



$ ->
  $el = $('#sections-matches-scorecard')
  if $el.length
    new ScorecardViewController($el)

【问题讨论】:

    标签: jquery ajax ruby-on-rails-3.2 google-dfp


    【解决方案1】:

    查看我创建的插件:https://github.com/coop182/jquery.dfp.js

    它允许您使用 jQuery 控制 DFP...它允许您选择何时加载 DFP,这将帮助您使用动态创建的元素。

    如果您有任何问题,请在此处或 github 上告诉我。

    编辑:抱歉刚刚意识到我已经回答了您的其他问题之一,让您了解我的插件...可能不是您想要的我猜...但我有一个您想要的示例无论如何...它可能会帮助您找出代码出错的地方。

    <!doctype html>
    <html lang="en">
    <head>
      <meta charset="utf-8" />
      <title>jQuery UI Tabs - Content via Ajax</title>
      <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" />
      <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
      <script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>
      <script src="https://raw.github.com/coop182/jquery.dfp.js/master/jquery.dfp.js"></script>
      <script>
      $(function() {
        $( "#tabs" ).tabs({
          load: function( event, ui ) {
            $('.adunit:not(".display-block")').dfp({
              dfpID: '15572793',
              enableSingleRequest: false
            });
          }
        });
      });
      </script>
    </head>
    <body>
    <div id="tabs">
      <ul>
        <li><a href="#tabs-1">Preloaded</a></li>
        <li><a href="1.html">Tab 1</a></li>
        <li><a href="2.html">Tab 2</a></li>
        <li><a href="3.html">Tab 3</a></li>
        <li><a href="4.html">Tab 4</a></li>
      </ul>
      <div id="tabs-1">
        <p>Proin elit arcu, rutrum commodo, vehicula tempus, commodo a, risus. Curabitur nec arcu. Donec sollicitudin mi sit amet mauris. Nam elementum quam ullamcorper ante. Etiam aliquet massa et lorem. Mauris dapibus lacus auctor risus. Aenean tempor ullamcorper leo. Vivamus sed magna quis ligula eleifend adipiscing. Duis orci. Aliquam sodales tortor vitae ipsum. Aliquam nulla. Duis aliquam molestie erat. Ut et mauris vel pede varius sollicitudin. Sed ut dolor nec orci tincidunt interdum. Phasellus ipsum. Nunc tristique tempus lectus.</p>
      </div>
    </div>
    </body>
    </html>
    

    1.html

    Tab 1 <div class="adunit" data-adunit="Leader" data-dimensions="728x90"></div>
    

    2.html

    Tab 2 <div class="adunit" data-adunit="Button" data-dimensions="160x180"></div>
    

    3.html

    Tab 3 <div class="adunit" data-adunit="Skyscraper" data-dimensions="160x600"></div>
    

    4.html

    Tab 4 <div class="adunit" data-adunit="Footer" data-dimensions="468x60"></div>
    

    【讨论】:

    • 感谢您的链接。我目前正在使用特定于 Rails 的 gem。但是我会对你的插件进行破解,看看我是否可以让它工作。很快回来报告
    • 我真的很想谈谈如何将它变成 Rails 的宝石?无论如何,我现在要为我们的项目继续它。所以生病让你知道我什么时候完成,这样你就可以做出贡献。再次感谢
    • 对我来说听起来不错,我没有玩过 Rails,但应该很容易上手......看起来你提到的其他 Rails 宝石可能松散地基于正在进行的工作无论如何,在我的回购中......所以它可能只是采用该gem的rails方面并结合我的js以获得适用于各种情况的gem的情况。无论如何,让我知道你过得怎么样......很高兴在这里见到一个新西兰人!
    猜你喜欢
    • 1970-01-01
    • 2015-07-29
    • 1970-01-01
    • 1970-01-01
    • 2013-02-23
    • 1970-01-01
    • 1970-01-01
    • 2015-09-06
    • 1970-01-01
    相关资源
    最近更新 更多