Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Attach a click() event to the google plus button?

I'd like to add a alert message on the page when a user clicks 'g+' button. how can i achieve this ?
here is code :

<g:plusone href="http://test.com//" annotation="inline" width="300"></g:plusone> 
<script type="text/javascript"> 
 (function() { 
    var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
    po.src = 'https://apis.google.com/js/plusone.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
  })();
</script>
like image 529
Manoj Prajapat Avatar asked Dec 20 '22 10:12

Manoj Prajapat


2 Answers

Just incase you want some code to get you started, the following markup will enable the interaction events in a +1 button:

<div
  class="g-plusone"
  data-expandto="bottom"
  data-onendinteraction="onEnded"
  data-onstartinteraction="onStarted"
  data-recommendations="false"
  data-annotation="inline"
  data-height="25"
  data-autoclose="true"
  data-callback="onCallback" 
  data-width="300"
>

The following code will handle the events:

function onStarted(args){
  console.log("started");
  console.log(args);
}
function onEnded(args){
  console.log("ended");
  console.log(args);
}
function onCallback(args){
  console.log("callback");
  console.log(args);
}

The callback will return the +1 state of the button, start/end interaction indicates the user state. You can see a demo of all the events here.

like image 131
class Avatar answered Jan 08 '23 04:01

class


Try reading their documentation which is actually quite good. They provide access to a callback function. See the section tag attributes.

https://developers.google.com/+/plugins/+1button/#script-parameters

like image 40
mrtsherman Avatar answered Jan 08 '23 02:01

mrtsherman