kytta / shareon

📯 Lightweight, stylish, and ethical share buttons for popular social networks
https://shareon.js.org/
MIT License
465 stars 25 forks source link

Feature request: Get event if button has been clicked #15

Closed dtslvr closed 4 years ago

dtslvr commented 4 years ago

Hello guys

It would be nice to get notified when a share button has been clicked (with the name of the social network).

Keep up the great work!

kytta commented 4 years ago

Hi, thank you for the idea! I have created shareon with one feature in mind — creating customizable buttons that are being populated with links. You can easily implement this behaviour yourself using onclick attribute or adding a click event listener:

<div class="shareon">
  <a class="facebook" onclick="userClicked('facebook')"></a>
  <a class="twitter" id="twitterBtn"></a>
</div>

<script>
  function userClicked(network) {
    console.log(network);
  }

  document
    .getElementById('twitterBtn')
    .addEventListener('click', function() { console.log('twitter'); });
</script>
dtslvr commented 4 years ago

Thanks a lot for the hint @NickKaramoff!