2

Basically on the home page I have the code snippet generated by Twitter Widget, when I load the page for the first time via url, the feed gets displayed, now I go to other page & come back to home page again, the twitter feed doesnt seem to be displayed.

I dont seem to find the reason behind this, is it something related to a SPA ? because if the load home page via URL it loads but when I navigate back & forth it doesn't display,
I just see the a tag Tweets by User

Mudassir Ali
  • 7,913
  • 4
  • 32
  • 60

1 Answers1

4

This is the widget code when we create a widget inside Twitter Settings(it's minified, I did format to make it readable)

<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>

as you can see the if(!d.getElementById(id)) this looks for the existence of the element, if it doesnt exist then it'll insert the feed, In my case this element exists but the widget was not rendering somehow when I navigate to some page & come back, so I removed that if statement and everything works perfectly, Only a single widget on the page.

Not the best solution but in future someone faces this problem this is a possible workaround !

Mudassir Ali
  • 7,913
  • 4
  • 32
  • 60
  • awesome, ive been trying to figure this out for hours! – dezman Aug 13 '13 at 15:44
  • @MudassirAli So it only works in ``component`` and not in ``templates``? – Jack Feb 06 '15 at 12:19
  • Well, I wrote this answer when emberjs hasn't introduced `component` yet. So, the important thing to note is whether the `element` with the id `twitter-wjs` exists or not – Mudassir Ali Feb 10 '15 at 06:57
  • `d.getElementsByTagName(s[0],p` should be `d.getElementsByTagName(s[0]),p`. But this solution is not working in Ember Components for route changing case. – Hasib Mahmud Apr 15 '15 at 14:33
  • This answer is very old, written when there weren't ember components back then – Mudassir Ali Apr 15 '15 at 16:02