成功推文后,执行回调+ Twitter [英] After successful tweet, execute the callback + Twitter
问题描述
我正在做在Twitter上分享的功能。我有分享按钮,当我点击它将打开一个推特小部件,并显示我的共享框。当我按下小部件的推文按钮时,它会在我的推特时间线上发布我的消息。
I am doing the "share on Twitter" functionality. I have share button and when I click it will open a widget of twitter and showing me the share box. When I will press on Tweet button of widget , it will post my message on my twitter timeline.
现在我想处理一个回调,当我推特成功时,流行音乐up不应该显示,我的网站应该重定向下一页。
now I want to handle a callback, when I tweet successfully, the pop up should not display and my website should redirect next page.
我参考了 Twitter的推文按钮是否有回调?这个问题但是没有按照我的要求工作。
I refereed Is there a callback for Twitter's Tweet Button? this question but not working as per my requirements.
Twitter提供活动,但它将在Tweet按钮上执行,这些按钮嵌入在我们的网站中。我尝试使用以下代码:
Twitter providing the events but it will execute on Tweet button which are embedded in our site. My tried with following code:
<a href="https://twitter.com/share" class="twitter-share-button" data-url="http://www.pinceladasdaweb.com.br/blog/" data-via="pinceladasdaweb" data-lang="pt" data-text="Pinceladas da Web">Tweetar</a>
Js代码:
window.twttr = (function (d,s,id) {
var t, js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return; js=d.createElement(s); js.id=id;
js.src="https://platform.twitter.com/widgets.js"; fjs.parentNode.insertBefore(js, fjs);
return window.twttr || (t = { _e: [], ready: function(f){ t._e.push(f) } });
}(document, "script", "twitter-wjs"));
twttr.ready(function (twttr) {
twttr.events.bind('tweet', function () {
alert('Tweeted!');
});
});
});
是否有成功推文后重定向到下一页的方法?
Is there a way to redirect to next page after successful tweet?
推荐答案
一般来说,推文回调没有方法或意图。我在成功推文后使用下面的黑客进行回调:
Generally there is no method or intent for a callback from a tweet. I used below hack to make a callback after a successful tweet:
window.twttr = (function (d,s,id) {
var t, js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return; js=d.createElement(s); js.id=id;
js.src="//platform.twitter.com/widgets.js"; fjs.parentNode.insertBefore(js, fjs);
return window.twttr || (t = { _e: [], ready: function(f){ t._e.push(f) } });
}(document, "script", "twitter-wjs"));
$(document).on('click','.twitter',function(){
var tweetUrl = 'https://twitter.com/intent/tweet?url='+window.location.href;
var x = screen.width/2 - 700/2;
var y = screen.height/2 - 450/2;
var child = window.open(tweetUrl, "popupWindow", "width=600, height=400,left="+x+",top="+y);
child.focus();
var timer = setInterval(checkChild, 1);
document.domain = 'example.com'; //Replace it with your domain
function checkChild() {
if(child.closed){
clearInterval(timer);
}
if(child.window && child.window.closed){ //Code in this condition will execute after successfull post
//Do your stuff here
console.log('I am here after a successful tweet.');
clearInterval(timer);
}
}
});
<a class="twitter" href="javascript:void(0)">Tweet</a>
这篇关于成功推文后,执行回调+ Twitter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!