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

编程入门 行业动态 更新时间:2024-10-28 07:31:26
本文介绍了推文成功后,执行回调+推特的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在执行在 Twitter 上分享"功能.我有分享按钮,当我点击它时会打开一个 twitter 小部件并显示我的分享框.当我按下小部件的 Tweet 按钮时,它会在我的推特时间线上发布我的消息.

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.

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

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/share" class="twitter-share-button" data-url="http://www.pinceladasdaweb.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/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?

推荐答案

通常没有从推文回调的方法或意图.我使用以下 hack 在成功推文后进行回调:

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/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/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';     //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>

这篇关于推文成功后,执行回调+推特的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-03-31 16:41:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/808899.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:回调   文成

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!