Google Plus一键 - 如何添加回调?

AnA*_*ice 9 javascript api jquery google-plus

我在我的网站上呈现了谷歌+按钮,如下所示:

在JS中:

    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);
Run Code Online (Sandbox Code Playgroud)

在html中:

<g:plusone size="medium" href="https://site.com"></g:plusone>
Run Code Online (Sandbox Code Playgroud)

如何为此添加回调以检测用户何时单击?我在这里看到了文档:https://developers.google.com/+/plugins/+1button/#jsapi没有看到如何使用当前渲染实现.谢谢

mim*_*ing 8

您可以使用回调属性将JavaScript回调添加到+1按钮标记.提供驻留在全局命名空间中的函数的名称.当用户点击+1按钮时会调用它.

以下是您的代码的外观:

<script>

   function myCallback(jsonParam) {

      alert("URL: " + jsonParam.href + " state: " + jsonParam.state);

   }

</script>

<g:plusone size="medium" href="https://site.com" callback="myCallback"></g:plusone>
Run Code Online (Sandbox Code Playgroud)

您可以在文档标记参数部分中了解有关此属性的更多信息.