I\'ve been doing a lot of research into Twitter\'s Embedded Timelines. I\'ve been trying to figure out if it is possible to know when the timeline is finished loading and
You could try using the Javascript factory instead of attribute binding. The createTimeline method returns a promise so you can chain your post load activities there. See the twitter documentation: https://dev.twitter.com/web/embedded-timelines/parameters
twttr.widgets.createTimeline(
"YOUR-WIDGET-ID-HERE",
document.getElementById("container"),
{
height: 400,
chrome: "nofooter",
linkColor: "#820bbb",
borderColor: "#a80000"
}
)
.then(function(){
DoSomething();
});
When you copy and paste the code you get from Twitter, you have to replace this:
<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>
With this:
<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";js.setAttribute('onload', "twttr.events.bind('rendered',function(e) {doSomething()});");fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
Of course, the doSomething function called above is your callback that runs when your embedded timeline loads and renders.
Also, I guess this solution doesn't work in Internet Explorer since it doesn't support onLoad events for script elements. Yet there are solutions for that.
Last, you can see my approach to this issue in the Twitter embedded timeline scraper I wrote.
I'm gonna post my solution here even if it's been 1month just in case someones finds this post again, what I had to do was to poll until the iframe had a width > 1 as an indicator for callback
if ($('.twitter-timeline').length) {
//Timeline exists is it rendered ?
interval_timeline = false;
interval_timeline = setInterval(function(){
console.log($('.twitter-timeline').width());
if ($('.twitter-timeline').hasClass('twitter-timeline-rendered')) {
if ($('.twitter-timeline').width() > 10) {
//Callback
clearInterval(interval_timeline);
DoWhatEverYouNeedHere();
}
}
},200);
}