سؤال

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

هل كانت مفيدة؟

المحلول

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 !

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top