How do I render new Twitter widget dynamically?

前端 未结 4 1915
误落风尘
误落风尘 2021-01-05 17:29

If I register a widget on Twitter, I get the following code:



        
相关标签:
4条回答
  • 2021-01-05 17:40

    you can have a single data-widget-id and filter out any tweet message feed by just adding,

        data-screen-name="AnyTwitterName"
    

    for an example

         <a class="twitter-timeline"  data-widget-id="6596840392xxxxxxxx"  data-screen-name="AnyTwitterName" ></a>
    
    0 讨论(0)
  • 2021-01-05 17:44

    use

    twttr.widgets.load(); 
    

    if you have loaded //platform.twitter.com/widgets.js already

    In my situation I doing like this: replacing content of some empty or previously timeline filled block to new link like yours

    <a class="twitter-timeline" href="https://twitter.com/vinto60utd" data-widget-id="283564783750483968">
        Tweets by   @vinto60utd</a> 
    

    then I call twttr.widgets.load(); and twitter do the rest.

    0 讨论(0)
  • 2021-01-05 18:00

    You can create widgets at run-time using Twitter for Websites JS.

    https://dev.twitter.com/web/embedded-timelines

    0 讨论(0)
  • 2021-01-05 18:02

    Change

    !function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");
    

    To

    function twit(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}
    twit(document,"script","twitter-wjs");
    
    0 讨论(0)
提交回复
热议问题