[英]Custom twitter 'Tweet Button' callback does not work for first click but works the second time
Everything is there in the title itself. 标题本身就是一切。 I am trying to create a custom tweet button with callback.
我正在尝试使用回调创建自定义推文按钮。 I have pasted the code below.
我已粘贴下面的代码。 I am not using the Twitter Button code from twitter as I have a multiple tweet buttons on the same page and I want to pass a unique id to each callback according to which button was clicked.
我没有使用来自Twitter的Twitter按钮代码,因为我在同一页面上有多个推文按钮,我想根据单击的按钮向每个回调传递一个唯一的ID。
First time the button is clicked, the popup opens for tweet and after tweeting, window closes but callback function is not called. 第一次单击该按钮,弹出窗口打开推文,在推文后,窗口关闭,但不调用回调函数。 Second time I click the same button (without reloading the page), the callback function is called!
第二次我点击相同的按钮(没有重新加载页面),调用回调函数! Any I idea why this is happening and how this can be corrected to work on first click?
我知道为什么会发生这种情况以及如何在第一次点击时纠正这个问题?
Thank you all. 谢谢你们。
<a href="#" target="_blank" id="twtShareLink"
onclick="return twOpenPopup('<URL>','<TEXT>','<UNIQUE_ID>')"
>Tweet It!</a>
JS: JS:
function twOpenPopup(url,text,unique_id){
twttr.events.bind('tweet',function(event){
alert('Here');
//Code that uses unique_id here;
});
var twturl="https://twitter.com/intent/tweet?url="+encodeURIComponent(url) +
"&count=none&source=tweetbutton&text=" + encodeURIComponent(text) + "&original_referer=" + encodeURIComponent('<?= $_SERVER['HTTP_HOST'] ?>');
document.getElementById("twtShareLink").href = twturl;
return true;
}
Because you're not binding your event until you click on the button. 因为在单击按钮之前,您不会绑定事件。 You need to bind the event outside the
twOpenPopup()
function. 您需要在
twOpenPopup()
函数之外绑定事件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.