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:\n\n'+answer.quote+'\n\nWhat will it tell you?">Tweet</a>'

twttr.widgets.load()

[Tools] Add a Dynamic Tweet Button to a Webpage的更多相关文章

  1. Using jQuery to add a dynamic “Back To Top” floating button with smooth scroll

    Ever read a really long blog post or article and then had to scroll all the way up to the top of the ...

  2. Tweet button with a callback – How to?

    原文: http://jaspreetchahal.org/tweet-button-with-a-callback-how-to/ 两种方式:1. 原生的button <a href=&quo ...

  3. ef code first transform,add ef power tools add-in,add tangible t4 editor for enhancement.

    use ef power tools, as to .edmx file,right click at view, choose generate database from model, then ...

  4. Linux Programe/Dynamic Shared Library Entry/Exit Point && Glibc Entry Point/Function

    目录 . 引言 . C/C++运行库 . 静态Glibc && 可执行文件 入口/终止函数 . 动态Glibc && 可执行文件 入口/终止函数 . 静态Glibc & ...

  5. magento产品成功添加到购物车后跳转到不同页面 添加 add to cart 按钮

    1 添加产品到购物车成功后是跳转到购物车页面或不跳转.这个在后台可以设置 system -> configuration -> After Adding a Product Redirec ...

  6. [AngularJS] Accessible Button Events

    Often buttons need to be handled by JavaScript, and if done improperly it can lead to accessibility ...

  7. 在toolbar里动态创建多个button(ext.net)

    private void setOneMenu() { string sql = "select id,name,gids from Config where name<>'高级 ...

  8. Dynamic proxy

    import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflec ...

  9. ASP.NET 动态创建文本框 TextBox (add TextBox to page dynamically)

    下面的函数每执行一次就生成一个TextBox(其实是<input type="Text">)    var i=0;     function changeIt()   ...

随机推荐

  1. 前端读者 | 从一行代码里面学点JavaScript

    本文来自 @张小俊128:链接:http://www.html-js.com/article/A-day-to-learn-from-a-line-of-code-inside-the-JavaScr ...

  2. Codeforces Round #496 (Div. 3) E2 - Median on Segments (General Case Edition)

    E2 - Median on Segments (General Case Edition) 题目大意:给你一个数组,求以m为中位数的区间个数. 思路:很巧秒的转换,我们把<= m 数记为1, ...

  3. 最短路-Floyd

    简介: 算法的特点:  弗洛伊德算法是解决任意两点间的最短路径的一种算法,可以正确处理有向图或有向图或负权(但不可存在负权回路)的最短路径问题,同时也被用于计算有向图的传递闭 包. 算法思想: 通过F ...

  4. CodeForces 738D Sea Battle

    抽屉原理. 先统计最多有$sum$个船可以放,假设打了$sum-a$枪都没打中$a$个船中的任意一个,那么再打$1$枪必中. #pragma comment(linker, "/STACK: ...

  5. TYVJ2002 扑克牌

    卢克生日那天,汉来找卢克玩扑克牌,玩着玩着汉觉得太没意思了,于是决定给卢克一个考验汉把一副扑克牌(54张)随机洗匀,倒扣着放成一摞.然后卢克从上往下一次翻开每张牌,每翻开一张黑桃,红桃,梅花或方块,就 ...

  6. 初生牛犊:Windows下Anti-sandboxes技术探究

    由于云端杀毒的流行,病毒基本上都会加上anti-sandboxes手段来躲避沙箱的探测,在这点上,由于一些原因,最近也一直在做这一块,所以算是总结一下吧. 一:什么是沙箱以及其他: 根据受控环境中的观 ...

  7. [BZOJ3529]数表

    假设$n\leq m$,我们先不考虑$\leq a$的限制 $\sum\limits_{i=1}^n\sum\limits_{j=1}^m\sigma((i,j))=\sum\limits_{T=1} ...

  8. 【最短路】【spfa】hdu6071 Lazy Running

    给你一个4个点的环,问你从2号点出发, 再回到2号点,长度>=K的最短路是多少.环上的边长度不超过30000. 跑出来所有dis(2,j)以后,然后for一遍j,根据dis(2,j)+t*2*w ...

  9. java 的环境搭建

    java.JDK 的搭建__本人是在360里下载的.也可以去其它的网站. java.jdk官网地址下载: https://download.oracle.com 二.也可以下载地址:http://do ...

  10. java中interface的完整表述

    我用一个工具:java Decompiler反编译工具查看jar包源码的时候,出现了以下代码: public abstract interface AbsITest{} 在网上搜索了一下: 我对这种情 ...