码迷,mamicode.com
首页 > Web开发 > 详细

[Tools] Add a Dynamic Tweet Button to a Webpage

时间:2019-02-06 09:33:00      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:mes   javascrip   htm   insert   wing   document   use   let   gets   

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

标签:mes   javascrip   htm   insert   wing   document   use   let   gets   

原文地址:https://www.cnblogs.com/Answer1215/p/10353429.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!