zoukankan      html  css  js  c++  java
  • [Tools] Add a Dynamic Tweet Button to a Webpage

    To let people easily share the patio11bot, we'll add a "Tweet" button to the page. You can easily add a static share button by going to https://publish.twitter.com/ and following the instructions there, but to make a dynamic tweet button is more difficult.

    We'll use the same share button, but we'll dynamically add it to the page with javascript, and then we have to tell the Twitter script to reload it as a widget with: twttr.widgets.load()

    Insert the script into the header: 

    <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>

    Add a placeholder in the html:

    <div id="tweet-button"></div>

    In script, we build dynamic message:

    document.getElementById("tweet-button").innerHTML = '<a href="https://twitter.com/share?ref_src=twsrc%5Etfw" class="twitter-share-button" data-show-count="false" data-size="large" data-via="chrisachard" data-text="patio11bot.com just told me:
    
    '+answer.quote+'
    
    What will it tell you?">Tweet</a>'
    
    twttr.widgets.load()
  • 相关阅读:
    前端调用后台接口下载word文档的两种方法
    Layui form表单提交注意事项
    JavaScript_Util_01
    心理
    小例子
    SQL分割字符串
    绘制10种不同颜色的散点图
    绘制散点图
    subplot的使用
    绘制正弦余弦
  • 原文地址:https://www.cnblogs.com/Answer1215/p/10353429.html
Copyright © 2011-2022 走看看