谷歌+1按钮 - 如何添加一个回调? [英] Google Plus One Button - How to add a callback?
问题描述
我有谷歌+按钮,在我的网站正在呈现如下:
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>
我怎么能回调到这个用户点击时检测到?我看到这里的文档:<一href=\"https://developers.google.com/+/plugins/+1button/#jsapi\">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
推荐答案
您可以用回调属性的JavaScript回调添加到您的+1按钮标记。供应驻留在全局命名空间的函数的名称。当用户点击+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.
下面就是你的code可能是这样的:
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.
这篇关于谷歌+1按钮 - 如何添加一个回调?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!