Add event listner on the click of the facebook and google+ icons generated through addthis.

StackOverflow https://stackoverflow.com/questions/17482043

  •  02-06-2022
  •  | 
  •  

Question

I want to add a custom code which will tigger when the user click on the facebook and the google plus link.

We have added

addthis.addEventListener('addthis.menu.open', eventHandler);
addthis.addEventListener('addthis.menu.close', eventHandler);
addthis.addEventListener('addthis.menu.share', eventHandler);

But non of them is fireing on the click of these two.

Was it helpful?

Solution

I was getting nothing and then figured that the addEventListener was probably firing before the object was in place, so I wrapped it in a $(document).ready()

<script type="text/javascript">
    // Alert a message when the user shares somewhere
    function shareEventHandler(evt) { 
        //console.log(evt); // look in the browser for the object details
        alert(evt.data.service);
    }

    $(document).ready(function(){
        addthis.addEventListener('addthis.menu.share', shareEventHandler);
    });
</script>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top