Load a Twitter widget with javascript?


Is there a way to draw a twitter widget to the page with javascript as opposed to the following:

<a class="twitter-timeline" href="<%@TwitterWidgetHREF%>" data-widget-id="<%@TwitterWidgetTSID%>"><%@TwitterWidgetTitle%></a>< script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script >

I’d like to give it a custom height that is being set in javascript.


You may be interested in twttr.widgets.createTimeline().


Thank you, that is exactly what I was looking for. Do you know what I might be missing here?


I keep getting “Uncaught ReferenceError: twttr is not defined” in the console.


Load Twitter’s widgets.js using an async snippet containing an async function queue in twttr.ready.

Pass any functions relying on Twitter’s widgets.js to twttr.ready, which will either place the function in a queue to be executed once Twitter’s widget.js has executed, or execute immediately if widgets.js is already available.

twttr.ready(function (twttr) {


I made the update. That seemed to work at first, but I’m now getting the same error message. I used BrowserStack before I left my friends house and tried a bunch of different browsers and it was working every time. As soon as I got home, I opened it on my machine and it didn’t work again.

I’m pretty sure I set it up the way you are suggesting. Could you please check it out again?


Thanks a lot for your help btw. I really appreciate it!