2013-12-18 96 views
1

我正在尝试捕获Google+按钮点击,但未成功。跟踪Google Plus按钮上的click()事件?

我在我的实现中使用了“onstartinteraction”,不幸的是,即使用户将鼠标悬停在G +按钮上,该方法也会被触发。

我试过使用“数据回调”,但是只有用户在弹出的Google+登录窗口中点击G +按钮&登录后才会触发此方法。 我的要求是当用户单击G +按钮时捕获点击。

任何帮助将不胜感激。谢谢。

这里的.cshtml:

<!DOCTYPE html> 
<html> 
<head> 
<title>Google Plus Click</title> 
@Scripts.Render("~/scripts/jquery-1.9.1.js") 
@Scripts.Render("https://apis.google.com/js/plusone.js") 
<meta name="view" content="width=device-width" /> 
</head> 
<body> 
<table cellspacing="0" border="0" cellpadding="0"> 
<tbody> 
<tr> 
<td> 
<div class="g-plusone" data-size="medium" data-annotation="none" data-onstartinteraction="plusClick"> 
</div> 
</td> 
</tr> 
</tbody> 
</table> 
</body> 
</html> 
<script type="text/javascript" language="javascript"> 
function plusClick(data) { 
alert('G PlusOne Button Clicked'); 
} 
</script> 

回答

0
<div class="g-plusone" data-size="medium" data-annotation="none" data-onstartinteraction="plusClick" onClick="plusClick.call(this,event)"> 

上用onclick宥可以解雇你的函数。 NB。 plusClick.call(this,event)里面的功能plus点击this范围是你点击的按钮,你的data是事件。

+0

对不起。 onClick没有帮助。它只是没有被解雇。可能是“g-plusone”类不允许我们使用onClick。 – user3114059

+0

呃...看到与波阿斯链接的纪念。 – Frogmouth