Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Twitter's embedded tweets be rendered dynamically?

Twitter's new-ish 'embedded tweets' feature is nice, but as far as I can tell the Twitter API's widgets.js can only render the embedded tweets at page load.

The doc page for embedded tweets is here: Embedded Tweets | Twitter Developers

It describes an oembed endpoint for "dynamically rendering" a tweet, but this only returns the bare HTML code that must still be transformed by widgets.js.

If I dynamically load some content via Ajax and insert it into the DOM, and that content includes the code for an embedded tweet, is there a way to get widgets.js to render that embedded tweet dynamically? A function or method call maybe?

like image 536
Charles Johnson Avatar asked Feb 23 '12 23:02

Charles Johnson


1 Answers

It's possible to do by calling twttr.widgets.load(). Pass in an HTMLElement as the first argument to limit the search for uninitialized widgets to that element. For example:

twttr.widgets.load(document.getElementById("container"))

Source: https://developer.twitter.com/en/docs/twitter-for-websites/javascript-api/guides/scripting-loading-and-initialization

like image 158
Peter Simonsson Avatar answered Oct 29 '22 21:10

Peter Simonsson