4

Im facing a problem that I don't get embedded tweet rendered in Firefox, though it gets rendered in Chrome.

I want to provide possibility for user to preview tweet via its link and render it within an Iframe (I have a few reasons for that), so I insert following block of code into my Iframe onload:

<blockquote class='twitter-tweet'><a hidden='true' href='LINK_TO_TWEET'></a></blockquote>
<script src='//platform.twitter.com/widgets.js' async='' charset='utf-8'></script>

It gets successfully inserted into an Iframe, it loads twitter.js, which finds blockquote.twitter-tweet element and tries to convert it into tweet, but I get error block generated instead:

<body>
<iframe id="twitter-widget-0" class="twitter-tweet twitter-tweet-rendered" frameborder="0" scrolling="no" allowtransparency="true" allowfullscreen="true" style="position: absolute; visibility: hidden; display: block; width: 0px; height: 0px; padding: 0px; border: medium none;">...</iframe>
<blockquote class="twitter-tweet twitter-tweet-error" lang="en-US" cards="hidden" dnt="true" data-twitter-extracted-i1467296456320670416="true">
<iframe id="rufous-sandbox" frameborder="0" scrolling="no" allowtransparency="true" allowfullscreen="true" style="position: absolute; visibility: hidden; display: none; width: 0px; height: 0px; padding: 0px; border: medium none;">...<iframe>
</body>

There are no errors in console. Does anybody have ideas?...

1 Answers1

0

Insert this script inside head of your iframe document

<script>
  window.twttr = (function(d, s, id) {
        var js, fjs = d.getElementsByTagName(s)[0],
          t = window.twttr || {};
        if (d.getElementById(id)) return t;
        js = d.createElement(s);
        js.id = id;
        js.src = "https://platform.twitter.com/widgets.js";
        fjs.parentNode.insertBefore(js, fjs);

        t._e = [];
        t.ready = function(f) {
            t._e.push(f);
        };

        return t;

    }(document, "script", "twitter-wjs"))
</script>

If you to need add more twitters after your iframe loaded, you can use:

yourIframe.contentWindow.twttr.widgets.load();

or you can create a twitter iframe based on your id, and pass a container like div, bloquote, etc.

yourIframe.contentWindow.twttr.widgets.createTweet(idTweet, containerHTML);