$("#create-widget").on("click", function (e) {
// create a twitter timeline widget
// see https://dev.twitter.com/web/javascript/creating-widgets
twttr.widgets.createTimeline(
"317788461761429504", // Widget ID from Ed's twitter account
$("#widget").get(0), // use .get(0) to access HTML Element
{
height: 300,
screenName: $("#screen_name").val()
}).then(function (element) {
console.log("timeline creation complete");
// called when timeline has been successfully created
// adjust width since twitter uses 520px as maximum
// see https://dev.twitter.com/web/embedded-timelines#dimensions
$(element).css("width", "100%");
}, function (status) {
console.log('Status' + status);
// called on failure, not sure what arguments twitter passes
// it appears to pass back the HTTP status from the API
// see https://dev.twitter.com/overview/api/response-codes
// so ((typeof status) === "number")
// I can also see that the JSON in the HTTP response header has
// an error message (string) which makes sense since this library call
// is presumably using the API (which includes an error message as well)
// but they don't seem to pass that to this callback
// they do log it in the JS console though
// see http://api.jquery.com/deferred.then/ for jQuery documentation
console.log("timeline creation failed");
});
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.