成功推文后,执行回调+ Twitter

我正在做“在Twitter上分享”的function。 我有分享按钮,当我点击它将打开一个推特小部件,并显示我的共享框。 当我按下小部件的推文按钮时,它会在我的推特时间线上发布我的消息。

现在我想处理一个回调,当我成功发推文时,弹出窗口不应该显示,我的网站应该重定向下一页。

我推荐是否有Twitter的推文按钮回调? 这个问题,但没有按照我的要求工作。

Twitter提供活动,但它将在Tweet按钮上执行,这些按钮嵌入在我们的网站中。 我试过以下代码:

 

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!'); }); }); 

});

成功推文后有没有办法重定向到下一页?

通常,没有方法或意图从推文回调。 在成功推文后我使用下面的黑客进行回调:

 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); } } });