在iFrame中渲染Div

时间:2018-07-17 00:39:14

标签: javascript html iframe

我试图将div渲染到iFrame中,每次这样做时,它都会在所有破坏它的地方都带有引号。在代码底部有一个ID为nativeadnx的div,功能renderNative会在其中渲染内容-问题是我想在300x300 iFrame中渲染内容,只要我尝试将内容变量中的iFrame会在一组引号内进行渲染,从而阻止任何内容的渲染-有解决此问题的简便方法吗?

 <script type="text/javascript">
  function renderNative(obj, targetId) {
    var link = obj.native.clickTrackers[0] + "clickenc=" + obj.native.clickUrl;
    var title = obj.native.title;
    var text = obj.native.body;
    var img = obj.native.image.url;
    var img_width = obj.native.image.width;
    var img_height = obj.native.image.height;
    var sponsored = obj.native.sponsoredBy;
    var cta = obj.native.cta;

    var content =

      '<div class="tile standard image story">' +
      '<div class="interior">' +
      '<div class="tileContentHolder">' +
      '<a href="' + link + '" target="_blank">' +
      '<time class="red-square livestamp">' +
      'Sponsored by ' + sponsored +
      '</time>' +
      '<div class="tileImage"> ' +
      '<img src="' + img + '" class="titleImage" width="280" height="140">' +
      '</div>' +
      '</a>' +
      '<div class="tileContent">' +
      '<a class="hookLink" href="' + link + '" target="_blank">' +
      '<h3>' + title + '</h3>' +
      '</a>' +
      '<div class="tileContentText">' +
      '<p>' +
      '<a class="textLink" href="' + link + '" target="_blank">' + text + '</a>' +
      '</p>' +
      '</div>' +
      '</div>' +
      '</div>' +
      '</div>' +
      '</div>';
    document.getElementById(targetId).innerHTML = content;
  }

  var apntag = apntag || {};
  apntag.anq = apntag.anq || [];



  (function() {
    var d = document,
      scr = d.createElement('script'),
      pro = d.location.protocol,
      tar = d.getElementsByTagName("head")[0];
    scr.type = 'text/javascript';
    scr.async = true;
    scr.src = ((pro === 'https:') ? 'https' : 'http') + '://acdn.adnxs.com/ast/ast.js';
    if (!apntag.l) {
      apntag.l = true;
      tar.insertBefore(scr, tar.firstChild);
    }
  })();

  apntag.anq.push(function() {
    var iframe = document.getElementById("native_if");
    apntag.setPageOpts({
      member: 8816,
    });
    apntag.defineTag({
      targetId: 'nativeadnx',
      tagId: 13436793,
      allowedFormats: ['native'],
      targetingParams: {},
      native: {
        title: {
          required: false
        },
        body: {
          required: false,
          max_length: 300
        },
        image: {
          required: false
        },
        icon: {
          required: false
        },
        sponsoredBy: {
          required: false
        },
        cta: {
          required: false
        },
        clickUrl: {
          required: false
        }
      }
    });

    apntag.onEvent('adAvailable', 'nativeadnx', function(obj) {
      renderNative(obj, 'nativeadnx');
      apntag.fireImpressionTrackers(obj);

    });
    apntag.loadTags();
  });

</script>

<div id="nativeadnx">

</div>

0 个答案:

没有答案