Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I render new Twitter widget dynamically?

If I register a widget on Twitter, I get the following code:

<a class="twitter-timeline" href="https://twitter.com/vinto60utd" data-widget-id="283564783750483968">Tweets by @vinto60utd</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id))>>>{js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}>(document,"script","twitter-wjs");</script>

If I put this code as it is on my page, I see the Twitter widget as I wanted. How do I render my widgets dynamically or on the execution of some event (like button click)?

like image 713
Vinit Gaikwad Avatar asked Jan 27 '13 08:01

Vinit Gaikwad


People also ask

Can Twitter be a widget?

Using a Twitter widget, you can show Twitter content on your website and engage your visitors.

How do I add a Twitter widget to HTML?

Go to https://publish.twitter.com/. Enter the URL of the timeline you'd like to embed. Customize the design by specifying the height and theme (light or dark) to match your website. Copy and paste the code into the HTML of your website wherever you would like the timeline to appear.

How do I use Twitter widget?

Go to 'Sources' and connect your Twitter account. Choose which type of Twitter source of posts you want to connect: hashtag, mentions, or your Twitter account. Customize and moderate the widget. Copy and embed the code on your website.


1 Answers

use

twttr.widgets.load(); 

if you have loaded //platform.twitter.com/widgets.js already

In my situation I doing like this: replacing content of some empty or previously timeline filled block to new link like yours

<a class="twitter-timeline" href="https://twitter.com/vinto60utd" data-widget-id="283564783750483968">
    Tweets by   @vinto60utd</a> 

then I call twttr.widgets.load(); and twitter do the rest.

like image 145
Andrew Avatar answered Sep 22 '22 11:09

Andrew