2013-12-18 39 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