Create a simple Twitter share button

Twitter (for now) has a very simple sharing intent. There is no need to include a massive script into your sites to offer a "share this" button.

For example, click the following link:

Tell Twitter about this

Here is a form and a simple, vanilla JavaScript to use this API.

Create a one-off-button

Enter your information (leave empty what you don't want)

Share on Twitter

Use sharebutton.js

This simple script can help you dynamically alter a share button. See the source of this page as an example.

Share Beedogs

1) Make sure you have a link in your HTML, like this:

<a target="_blank" id="myshare"
  href="https://twitter.com/intent/tweet">
  Share Beedogs
</a>

2) Include sharebutton.js

  <script src="sharebutton.js"></script>

3) Set the configuration

sharebutton.config.hashtags = 'dogs,beecostumes';
sharebutton.config.link = 'http://beedogs.com';
sharebutton.config.account = 'codepo8';

4) Give the script the DOM selector and the text to set

  sharebutton.set(
    '#twittershare',
    'Best dogs in bee costumes site on the web'
  );

You can of course keep the config, and simply re-set the text or have it as a result of a concatenation.