Load a Twitter widget with javascript?


#1

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.


#2

You may be interested in twttr.widgets.createTimeline().
https://dev.twitter.com/web/javascript/creating-widgets


#3

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

http://the-leader_com.nestage.gat.atl.publicus.com/twitterwidgettestingsections123?nocache=1

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


#4

Load Twitter’s widgets.js using an async snippet containing an async function queue in twttr.ready.
https://dev.twitter.com/web/javascript/loading

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) {
  twttr.widgets.createTimeline();
});

#5

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?

http://the-leader_com.nestage.gat.atl.publicus.com/twitterwidgettestingsections123?nocache=1

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


#6