Google Plus One Button - 如何添加回调? [英] Google Plus One Button - How to add a callback?

查看:34
本文介绍了Google Plus One Button - 如何添加回调?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站上呈现的 google+ 按钮如下所示:

I have the google+ button being rendered on my site as follows:

在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);

在 html 中:

<g:plusone size="medium" href="https://site.com"></g:plusone>

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

How can I add a callback to this to detect when the user has clicked? I see the docs here: https://developers.google.com/+/plugins/+1button/#jsapi not seeing how to implement with the current render. Thanks

推荐答案

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

You can add a JavaScript callback using a callback attribute to your +1 button markup. Supply the name of a function that resides in the global namespace. It will be called when a user clicks on the +1 button.

您的代码可能如下所示:

Here's what your code might look like:

<script>

   function myCallback(jsonParam) {

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

   }

</script>

<g:plusone size="medium" href="https://site.com" callback="myCallback"></g:plusone>

您可以在文档.

You can learn more about this attribute in the tag parameters section of the documentation.

这篇关于Google Plus One Button - 如何添加回调?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆